Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed some error and added one new feature #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

manan-desai
Copy link

hello,
I have just fixed an error, which occurred when i used this module with local ip(192.168.0.1 etc..). It returned https protocols insted of http. i added test as well.
Furthermore i have added one more argument for function, which is options. If user wants to customised https or http manually then s/he can pass custom https:true. Also I have written documentation for usage of new feature on mark down.
if you find any difficulties to understand changes, don't haste to ask me.

hello,
 I have just fixed an error, which occurred when i used this module with local ip(192.168.0.1 etc..). It retured https protocols insted of http. i added test as well.
Furthermore i have added one more argument for function, which is options. If user wnats to customized https or http manually then s/he can pass custom https:true. Also I have written documentation for usage of new feature on mark down.
if you find any difficulties to understand changes, sont hasited to ask me.
let protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:'
let protocol = https
? 'https:' // if NODE_ENV is production
: process.env.NODE_ENV == 'production'
Copy link
Owner

@jakeburden jakeburden Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

This seems to lock the protocol to https if process.env.NODE_ENV == 'production'.

In most cases I think this will be fine, but what if someone is testing their production build locally, over http?

I'm not sure if we should be changing things based on environment variables here. Thoughts?

@jakeburden
Copy link
Owner

Thank you so much @manan5439 for your contribution and for including tests!

I left one question, would love to get your thoughts on it. Back to you 🏓

@areksds
Copy link

areksds commented Sep 24, 2020

Hi @jekrb! Could you possibly merge this fix and remove the https defaulting for production for the reasons you stated? My fetch calls are breaking 😓

@jakeburden
Copy link
Owner

@areksds have you tested this change to see if it fixes the problem? I think you can do npm install manan5439/next-absolute-url to pull this down into your project and check it out.

I haven't had time to test this myself (I need to lean on community contributions at the moment 🙇), I'd feel much more comfortable merging this change sooner if you can confirm that it works for you.

@areksds
Copy link

areksds commented Sep 24, 2020

@jekrb just tested on localhost and production. It does make all localhost requests (127.0.0.1, etc.) http by default which is great, but since production is forced as https that only fixes half of the problem 🙃

Is there any way to just check what the incoming request's protocol is and use that as the protocol instead of setting it with a regex / checking whether it's a production build?

Thanks for your time!

@jakeburden
Copy link
Owner

just tested on localhost and production. It does make all localhost requests (127.0.0.1, etc.) http by default which is great, but since production is forced as https that only fixes half of the problem

@areksds just out of curiosity, are all your environments http?

If so, a quick fix could be:

const { host } = absoluteUrl(req)
const apiURL = `http://${host}/api/your_endpoint.js`

At least until we resolve all the issues with this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants