jakeburden / next-absolute-url

Get the absolute URL of your Next.js app (optionally set a localhost dev URL)
300 stars 30 forks source link

Failing data calls as protocol is always https in production #14

Open xeoneux opened 4 years ago

xeoneux commented 4 years ago

I don't use https for my staging server and the calls there fail because the protocol is always https if the host isn't localhost. How can we fix this? Should it read the protocol from window.location if window is available?

jakeburden commented 4 years ago

Indeed! This is a known issue: https://github.com/jekrb/next-absolute-url/issues/12

The fix is to replace the regex we're using with window.location as you said.

I just haven't made the update yet. To be honest, I've been mostly hands-off with the module. All the most recent changes have pull requests from the community. I'd happily accept a community contribution to fix this bug!

A work around until this gets updated could be to just do:

let { protocol, host } = absoluteUrl(req)
if (window && window.location.href === stagingServerUrl) {
  protocol = `http:`
}
hugotox commented 3 years ago

protocol should be a setting from the env file. This condition can be removed from the function and use something like

protocol = process.env.APP_PROTOCOL ?? 'http:'
tajultonim commented 2 years ago

You may consider nextjs-url package