Is there a way to rewrite a query parameter in route?

Is there a way to rewrite a query parameter in the route?
For example (pseudocode):

router.get('/route/:path*?queryParam=${value}', ({ proxy }) => {
  proxy('origin', { path: '/route/:path*?queryParam=${newValue}' });
});

Thanks.

P.S. I wanted to add tags for this topic called caching and routing but there are no one available and I cannot create them.

How is newValue derived? If it’s a constant, you should be able to just add it to the path option. If it’s computed, you can use transformRequest, but keep in mind that will send the request through the serverless cloud. So you would only want to do that if you can cache the result.

1 Like

We’ve now updated the settings to allow non-admin users to be able to create new tags for their posts. You should be able to create/add new tags.

1 Like

Thanks. In my case it’s a constant, transformRequest helped here.

The final code example I got:

router.get('/route/:path*', ({ cache, proxy, removeResponseHeader }) => {
  removeResponseHeader('set-cookie');
  cache(CACHE_ASSETS);
  proxy('origin', {
    path: '/route/:path*',
    transformRequest: (request) => {
      const url = new URL(`https://example.com${request.url}`);
      const customValue = 'customValue';
      url.searchParams.set('queryParam', customValue);
      request.url = url.pathname + url.search;
    },
  });
});