nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

Make port optional #100

Closed dekadentno closed 4 years ago

dekadentno commented 4 years ago

What problem does this feature solve?

The port should be optional because there are many public (and non public) APIs that don't require the port in the Request URL.

What does the proposed changes look like?

In nuxt.config.js it should be possible to do

  http: {
    host: 'bla.bla.com',
    port: null, // or `false`
    prefix: '/v1' 
  }
dekadentno commented 4 years ago

I can try to resolve this and submit a pull request, but I am not sure why the port would be mandatory in the first place, maybe there's a reason but I don't see it.

ricardogobbosouza commented 4 years ago

Hi @dekadentno Just use the baseURL option

http: {
  baseURL: 'https://bla.bla.com/v1'
}
dekadentno commented 4 years ago

Hi @dekadentno Just use the baseURL option

http: {
  baseURL: 'https://bla.bla.com/v1'
}

Hi @ricardogobbosouza I've tried that. Also not possible because it automatically adds the default port (3000) at the end of the baseURL. Check line 20 here: https://github.com/nuxt/http/blob/dev/lib/module.js

ricardogobbosouza commented 4 years ago

The options are overwritten, see https://github.com/nuxt/http/blob/dev/lib/module.js#L38

dekadentno commented 4 years ago

The options are overwritten, see https://github.com/nuxt/http/blob/dev/lib/module.js#L38

I understand what you are trying to say, but I still get the default port at the end of my baseURL on every request. My nuxt.config.js looks just like the one you wrote in your comment.

Edit: I'll make a repo with my problem this weekend.

ricardogobbosouza commented 4 years ago

@dekadentno I await the Repo

pi0 commented 4 years ago

I agree with @ricardogobbosouza to use baseURL to override. But could be also nice enhancenment to omit the port if is matching scheme (https/443 http/80)

dekadentno commented 4 years ago

Thank you for your answers and your time @ricardogobbosouza @pi0 I am very ashamed but I have to let you know that the source of my problems was in my baseUrl because the currect spelling is baseURL 😅 I noticed that right now while trying to reproduce my problem in a separate repo so I can upload it for you guys.

I hope my mistake will help some future lurkers because I spent more than a week on this issue in vain.

pi0 commented 4 years ago

@dekadentno Actually nothing to sorry and thanks for report. I saw baseUrl misspelling multiple times. It is not module bug but a DX bug that we should handle properly. Will push fix for both :)