Using rewrites to connect projects, works on local but not on server

116 Views Asked by At

I am using rewrites to connect projects on Vercel. I can run the program on localhost without issue. I can even rewrite local main project to a deployed project. When I try to rewrite from deployed main project to deployed secondary project, the page comes up blank. Stating that page is not working from too many redirects, try clearing cookies. What am I missing? Basically, it works on local but not on server.

/** @type {import('next').NextConfig} */
const {
  PROJECT1_URL = 'https://filename1.vercel.app/',
  PROJECT2_URL = 'https://filename2.vercel.app/',
  PROJECT3_URL = 'https://filename3.vercel.app/',
} = process.env
const nextConfig = {
  reactStrictMode: true,
  basePath: "",
  async rewrites() {
    return [
      {
        source: '/:path*',
        destination: `/:path*`,
      },
      // PROJECT1
      {
        source: '/first',
        destination: `${PROJECT1_URL}/first`,
      },
      {
        source: '/first/:path*',
        destination: `${PROJECT1_URL}/first/:path*`,
      },
      // PROJECT2
      {
        source: '/second',
        destination: `${PROJECT2_URL}/second`,
      },
      {
        source: '/second/:path*',
        destination: `${PROJECT2_URL}/second/:path*`,
      },
      // PROJECT3
      {
        source: '/third',
        destination: `${PROJECT3_URL}/third`,
      },
      {
        source: '/third/:path*',
        destination: `${PROJECT3_URL}/third/:path*`,
      },
    ]
  }
};

module.exports = nextConfig;
0

There are 0 best solutions below