AI Gateway and AI SDK Integration
Running Next.js in ChatGPT: How to Build ChatGPT Apps

Running Next.js in ChatGPT: How to Build ChatGPT Apps

10/15/2025

What this post added

This post details the technical challenges and solutions for running a Next.js application within ChatGPT's nested iframe architecture. It addresses issues with asset loading by using `assetPrefix`, relative URL resolution by implementing a `<base>` HTML element, browser history leaks by patching `history.pushState` and `history.replaceState`, fetch request rewriting for client-side navigation by patching `window.fetch`, and CORS issues by implementing middleware to handle OPTIONS preflight requests and add CORS headers. It also covers patching parent frame modifications and ensuring external links navigate correctly.

Read the original post ↗