Correct way to proxy?

I have multiple sites e.g. dashboard, marketing site.

I am site up Start on my dashboard and i want to proxy to the marketing site.

I first tried Nitro config but no matter what layout of this i tried it didn't seem to work. It would always proxy to the marketing site ignoring the dashboard routes.

  nitro({
    routeRules: {
      '/**': {
        proxy: {
          to: 'http://localhost:3001/**',
        },
      },
      '/dashboard/**': {},
   },
}),


Then I tried making a global middleware function but that didn't seem to work and would return "This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE"

export const proxyMarketing = createMiddleware().server(async ({ next, request }) => {
  const path = request?.url ? new URL(request.url).pathname : '';

  if (DASHBOARD_PATHS.some((p) => path.startsWith(p))) {
    return next();
  }

  return await fetch(`http://localhost:3001${path}`, {
    method: request.method,
    headers: request.headers,
    body: request.method !== 'GET' ? request.body : undefined,
  });
});


What would be the ideal way to implement this (if possible)?
Was this page helpful?