2

I'm currently doing an app with Next.js 8.0.3.

Everything is fine in local. However I have some troubles when I deploy the app using Caddy.

About my Next.js part I'm using a Custom server and to serve this server I'm doing this:

next build
NODE_ENV=production node server.js

The problem itself is about routing the app to a subpath like /beta to run all the app inside this subpath.

Caddyfile

localhost:8000

proxy /beta http://localhost:3000/ 

When I run the app opening http://localhost:8000/beta in the browser, the HTML is loaded correctly but aren't loaded all the styles, assets and javascript files. Neither the navigation between pages. It's looking these files behind /, and I was expecting behind /beta.

devtools

Copying the url that is failing and trying to find the correct path adding /beta, the files aren't there neither...

file

Nevertheless, without the subpath /beta (if I use directly the root /) everything is working fine. But is not the solution that I'm looking for because I have more apps running behind the same domain.

There is a workaround that solve this is this particular example. Is to proxy also /_next and /static. But is not a good solution for me, for different reasons:

  1. Is not possible to run more than 1 Next.js app like /beta, /alpha.
  2. This solution don't fix the navigation between pages.
  3. I want to fix this (if is possible) in the Next.js part, not in Caddy part doing a workaround.

Looks that is something regarding about the Next.js part. But I'm quite lost about it. I tried to change the assetPrefix: '/beta', and then is looking for the files on /beta/file instead of /file. But the files aren't there neither...

Can somebody help me?

Aral Roca
  • 5,442
  • 8
  • 47
  • 78

0 Answers0