sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

Redirect to different domain result in invalid url #450

Closed JanStevens closed 1 week ago

JanStevens commented 1 week ago

Hi,

I noticed in the logs that redirects to different domain results in a very odd constructed url.

In my next.config.js file I have the following defined

{
  redirects: [
     {
        source: '/events/beast-house/tickets',
        destination: 'https://nofomo.com/collections/beast-house',
        permanent: false,
        basePath: false,
      },
  ]
}

In the logs I see that protocol already returns https://

INFO urlParts {
  pathname: '/collections/beast-house',
  protocol: 'https://',
  hostname: 'nofomo.com',
  queryString: ''
}
INFO value /en/events/beast-house/tickets
INFO    redirect {
  type: 'core',
  statusCode: 307,
  headers: {
    Location: 'https:////nofomo.com/collections/beast-house?eventSlug=beast-house&__nextDataReq=1'
  },
  body: '',
  isBase64Encoded: false
}

I think this is caused by this code (last 3 lines)

https://github.com/sst/open-next/blob/9d632d1bd5c3a8d7e7bbd13ae9daaca68da9284e/packages/open-next/src/core/routing/matcher.ts#L187-L220

khuezy commented 1 week ago

Great catch!