NextJS seems to have no way to reconfigure the base path (vercel/next.js#16059).
Some propose a reverse proxy, but because static pages embed the basePrefix into them this also doesn't work well.
The alternative is quite undesirable -- building at runtime.
Here, we use a hopefully unique string /__ENTRYPOINT__
as the entrypoint, this allows us to just replace this string
in all the next-built files at startup when we know the actual entrypoint.
Once building with this approach, the entrypoint can be customized, this also works for images, API endpoints, and more.
Tested on next@^12
NOTE: No longer works in next@^13
Complete repo for testing this: https://github.com/u8sand/test-nextjs-runtime-entrypoint-reconfig
The assumption here is that you're building your NextJS application with Docker, these files would be put in the root of your repo and you build with
docker build -t your-tag .
then you can run with arbitrary entrypoints i.e.
docker run -p 3000:3000 -e NEXT_PUBLIC_ENTRYPOINT=/myentrypoint -it your-tag
thx !!!! it's amazing