serverless-next.js
serverless-next.js copied to clipboard
Rewrites don't work with special symbols in URL
Issue Summary
Rewrites don't work with special symbols in URL
- no-op rewrites don't work with paths that include symbols like
@
and=
- external rewrites will build incorrect destination routes for paths that include symbols like
@
and=
No-op rewrites example:
rewrite config:
{
source: '/:path*',
destination: '/:path*',
},
{
source: "/:path*",
destination: `https://external.app/:path*`
}
PageManifest:
pageManifest = {
pages: {
dynamic: [],
html: {
dynamic: {},
nonDynamic: {}
},
ssg: {
dynamic: {},
nonDynamic: {},
notFound: {}
},
ssr: {
dynamic: {},
nonDynamic: {}
}
}
};
Actual behavior
input URL: /@iamatest
rewrite result: /%40iamatest
input URL: /iamatest=
rewrite result: /iamatest%3D
Expected behavior
according to how Next.js server rewrites work
input URL: /@iamatest
rewrite result: https://external.app/@iamatest
input URL: /iamatest=
rewrite result: https://external.app/iamatest=
External rewrites example:
rewrite config:
{
source: "/:path*",
destination: `https://external.app/:path*`
}
Actual behavior
input URL: /@iamatest
rewrite result: https://external.app/%40iamatest
input URL: /iamatest=
rewrite result: https://external.app/iamatest%3D
Expected behavior
according to how Next.js server rewrites work
input URL: /@iamatest
rewrite result: https://external.app/@iamatest
input URL: /iamatest=
rewrite result: https://external.app/iamatest=
Results from above show that rewrites create incorrect URLs when symbols like @
and =
are used.
In my case, this causes an additional problem because the external.app
redirects to the correct URL and I get an infinite loop of redirects:
- a user requests
https://next.js.app/@iamatest
- next.js.app rewrites to
https://external.app/%40iamatest
- external.app redirects to
https://next.js.app/@iamatest
- ... repeat ...
Versions
- @sls-next/serverless-component version: 3.7.0
- Next.js version: 11.1.4
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. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if 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.
Just to chime in, I experienced this issue as well working on this for a side project. We were trying to use the #
symbol at first, but ended up nixing it because it just never worked and I wasn't going to fork it.
Inspected the code referenced by @sleukhin and don't see a reason to encode/decode URLs at least from point of tests provided. @dphang I am about to investigate the problem with a fix but need a bit more context beforehands.