question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rewrite adds query param when re-appending a matched path param to the destination

See original GitHub issue

Bug 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

  1. Create a new next app

  2. Create a custom next.config.js:

module.exports = {
  async rewrites() {
    return [
      {
        source: "/api/:route*",
        destination: "https://postman-echo.com/:route*",
      },
    ];
  },
};

  1. Start next: yarn next dev

  2. Open up http://localhost:3000/api/get

  3. 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.

  1. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ijjkcommented, Jul 29, 2020

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

1reaction
ijjkcommented, Aug 14, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found