NextJS Redirect - req.headers.referer is missing - How to get original URL?
Asked Answered
C

0

9

I cannot figure out how to retrieve the original URL request from a Next.js redirect. Actually the code works as expected on my local server, but the information disappear on production.

My next.config.ts includes:

{
    source: '/user/:path*',
    destination: '/api/forward/forward',
    permanent: true,
}

While running on local I have the following:

...
'postman-token': '4d592b2f-a759-415c-a775-14e838f25d1e',
  'accept-encoding': 'gzip, deflate, br',
  connection: 'keep-alive',
  'content-length': '3',
  referer: 'http://localhost:3000/user/5f8d46425afbfe125bc0277c/balances/2970022',
  host: 'localhost:3000'
...

So everything is good here, I can use the referer.

Unfortunately, I cannot retrieve the original URL from the request in production; the only thing I get is:

{
 accept: 'application/json',
 authorization: 'bearer XXXXX',
 'client-id': 'YYYYY',
 'content-type': 'application/json',
 'content-length': '147',
 host: 'www.CCC.com',
 'accept-encoding': 'gzip',
 'user-agent': 'okhttp/4.9.1',
 'x-forwarded-proto': 'https',
 'x-forwarded-port': '443',
 'x-forwarded-for': '176.145.84.153',
 forwarded: 'proto=https;for=176.145.XX.XXX:2112;by=185.42.XXX.XXX',
 'sozu-id': '...'
}

I would really appreciate if someone know how I can get the initial URL in order to forward properly.

Carbylamine answered 8/11, 2021 at 16:16 Comment(1)
Were you able to get the request URL in the server-side code? I am also unable to find a way to get the client-side request URL in the getServerSideProps method. Please suggest. Thanks!Enjoin

© 2022 - 2024 — McMap. All rights reserved.