I'm setting up a NextJS 13 app under a subpath (/my-app) on my host. But it seems that it only works partially, it also feels that I'm fixing one thing and then another thing pops up.
I tried the following things:
I tried setting the base path in next.config.js, but it added an extra /my-app on the host, the result was /my-app/my-app as an index page.
I tried setting only the assetPrefix with /my-app. And that seems to work to some extent, except for the chunks loaded by NextJS when visiting the page, it requests them on the root of the host instead of prefixing them with /my-app.
I have a nextAuth middleware to redirect the user to /my-app/api/auth/signin but I have to inject my own environment variable base path to get it to redirect properly.
export default function middleware(req: NextRequest) {
const logger = getLogger('middleware');
logger.debug('NEXT_PUBLIC_BASE_PATH: ' + process.env['NEXT_PUBLIC_BASE_PATH']);
if (process.env['NEXT_PUBLIC_BASE_PATH']) {
req.nextUrl.basePath = process.env['NEXT_PUBLIC_BASE_PATH'];
}
// @ts-ignore
return withAuth(req);
}
Any idea how to configure this properly?