serverless-next.js
serverless-next.js copied to clipboard
next.config.js rewrites, when type is 'host', got host=null after rewrite.
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
oralpha
@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 oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.
@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
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.)
What is the status on the 'has' in rewrite?
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',
},
];
}
};