I am currently in the process of setting up multiple Vercel/Next.js projects under one domain, as recommended in this helpful guide.
Given that each of my apps have unique requirements, it makes sense for me to separate them into their own projects.
The main Next.js project will be running on mysite.com
. This project includes rewrites to the other projects:
const rewrites = async () => [
{
source: "/topic/",
destination: "https://forums.mysite.com/topic/",
},
{
source: "/topic/:match*",
destination: "https://forums.mysite.com/topic/:match*",
},
];
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
rewrites,
};
module.exports = nextConfig;
While these rewrites are somewhat functional, there seems to be an issue. When I try to access mysite.com/topic/
, Next.js attempts to load content from forums.mysite.com
, but fails to display it properly due to missing JavaScript scripts resulting in a 404 error.
Essentially, it is trying to fetch scripts from forums.mysite.com
on the domain of mysite.com
, where they do not exist.
Is there a workaround for this situation? It appears to be a significant oversight, despite being suggested as the method by Next.js in their documentation.
Any suggestions on how to resolve this issue?