Rewrite adds query param when re-appending a matched path param to the destination
See original GitHub issueBug report
Describe the bug
A rewrite from /source/:route*
to http://my-api-server.example.org/destination/:route*
forwards a request sent to /source/foo
to http://my-api-server.example.org/destination/foo?route=foo
. The extra query param will lead to issues especially with API servers as in REST this might represent a filter criteria.
To Reproduce
-
Create a new next app
-
Create a custom next.config.js:
module.exports = {
async rewrites() {
return [
{
source: "/api/:route*",
destination: "https://postman-echo.com/:route*",
},
];
},
};
-
Start next:
yarn next dev
-
Open up
http://localhost:3000/api/get
-
The results includes
"url":"https://postman-echo.com/get?route=get"
Expected behavior
Params that are added to the destination path should not be included as a query param.
- The results includes
"url":"https://postman-echo.com/get"
Screenshots
n/a
System information
- Version of Next.js: 9.5.0
- Version of Node.js: n/a
Additional context
n/a
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Next JS Use query parameter as variable in rewrite
I'm having issues with extracting the query parameter from the source to be used again in the destination. Here is my current implementation:...
Read more >How to add query params in forward rewrite using Modify ...
I have an use case where I need to add query parameter for forward request to origin. Let's say based on a conditional...
Read more >29.2 Creating a RESTful Root Resource Class
The @PathParam annotation is a type of parameter that you can extract for use in your resource class. URI path parameters are extracted...
Read more >auto_route - Dart API docs - Pub.dev
Query parameters are accessed the same way, simply annotate the constructor parameter to hold the value of the query param with @QueryParam('optional-alias') ...
Read more >ExtractVariables policy | Apigee Edge
Matching URI paths, query parameters, headers, form parameters, and variables. When extracting information from a URI path, query parameters, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, this is the behavior currently since when rewriting the end-user doesn’t see the query values so we make all params available in the query automatically.
After discussion it looks like it would make sense to not add the params to the query automatically for rewrites if it is already used in the destination so we will be investigating this behavior
@pratheekhegde the issue you mentioned with the trailing slash and rewrites can be tracked in this issue https://github.com/vercel/next.js/issues/15700