serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

next.config.js rewrites, when type is 'host', got host=null after rewrite.

Open hotlong opened this issue 3 years ago • 4 comments

Issue Summary

the type 'host' in next.config.js rewrite it not working after deploy, Cloudwatch ERROR Could not compile destination /hosts/:host, returning null instead.

Actual behavior

When access homepage, it rewrite to hosts/[host].js ,but host variable is null.

Expected behavior

When access homepage, it rewrite to hosts/[host].js , and set host variable

Steps to reproduce

next.config.js sample

  async rewrites() {
    return [
      {
        has: [
          {
            type: 'host',
            value: '(?<host>.*)',
          },
        ],
        source: '/',
        destination: '/hosts/:host',
    }
  ]
}

or Check this sample project https://github.com/acorcutt/next-multi-host

Screenshots/Code/Configuration/Logs

Cloudwatch ERROR Could not compile destination /hosts/:host, returning null instead.

Versions

  • OS/Environment: Mac
  • @sls-next/serverless-component version: 3.4.0
  • Next.js version: 11.1.2

Additional context

Checklist

  • [x] You have reviewed the README and FAQs, which answers several common questions.
  • [x] You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible.
  • [x] You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

hotlong avatar Oct 13 '21 03:10 hotlong

@hotlong Pretty sure this is because this doesn't support the new object rewrites from Next.js, per the note (Note that object format is not yet supported.) in the README

jonahallibone avatar Oct 15 '21 19:10 jonahallibone

Yes this is because the new parameters in rewrites/redirects aren't supported yet, so it doesn't understand has. Hoping to add this feature once I've cleaned up the code a little more in preparation for other platforms (Lambda, etc.)

dphang avatar Oct 22 '21 08:10 dphang

What is the status on the 'has' in rewrite?

ghost avatar Feb 09 '22 14:02 ghost

I think I hit this problem as well... @dphang Can you confirm that a config like below will not work? Is the workaround to handle that in a page with ServerSideProps and return a redirect?

const nextConfig = {
  reactStrictMode: true,
  async redirects() {
    return [
        {
            source: '/someurl',
            has: [
                {
                    type: 'query',
                    key: 'jid',
                    value: '(?<jid>.*)',
                },
            ],
            permanent: false,
            destination: '/somepath/:jid',
        },
    ];
  }
};

lbustelo avatar Jun 16 '22 21:06 lbustelo