Next.js Discord

Discord Forum

next.config.ts redirect subdomain with regex

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
According to the AI over at gpt help I can create the following redirect to redirect from, say, foo.example.com -> example.com/bar

    {
      source: '/:path*',
      has: [
        {
          type: 'host',
          value: 'foo.(?<domain>.+?)/',
        },
      ],
      destination: 'https://:domain/bar/',
    },


But when I do that, and try to test it with unstable_getResponseFromNextConfig via a unit test like so:

    const response = await unstable_getResponseFromNextConfig({ url: 'https://foo.example.com', nextConfig })
    expect(getRedirectUrl(response))
      .toBe(`https://example.com/bar`)


the response generated comes back with a null location (either by asking for the location from the response object or by using getRedirectUrl


Am I entering my regex wrong, or is there perhaps a bug in the unstable_getResponseFromNextConfig? The GPT AI said it was a known issue, but IME AI's always say that to me once I question their initial answer.

Thanks!

0 Replies