nuxt / http

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

BaseURL incorrectly modified : ENOTFOUND localhost81 #120

Closed mathieucivel closed 4 years ago

mathieucivel commented 4 years ago

Version

v0.5.10

Reproduction link

https://jsfiddle.net/Lqrzf41m/

Steps to reproduce

I'm just using the module, in a empty nuxtServerInit action.

My baseURL is http://localhost:8081

async nuxtServerInit({ commit }, context) {
    try {
      const libs = await context.$http.$get('/api/libs/')
      commit('setLibs', libs)
    } catch (error) {
      console.error(error)
    }
}

What is expected ?

this.$http to use a valid baseURL.

What is actually happening?

ERROR request to http://localhost81/api/libs/ failed, reason: getaddrinfo ENOTFOUND localhost81

Additional comments?

Looks like this line causes the issue : https://github.com/nuxt/http/blob/dev/lib/module.js#L119https://github.com/nuxt/http/blob/dev/lib/module.js#L119

Manualy setting http.baseURL in nuxt config produces the same error.

Workaround

Use a port not starting by 80