nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 245 forks source link

baseURL is undefined on some pages and logs show "Error: connect ECONNREFUSED 127.0.0.1:80" #438

Closed bryceandy closed 3 years ago

bryceandy commented 4 years ago

Nuxt version 2.14.7

Axios module 5.12.2

Problem: (Occurring only in production)

Code sample

Page /inspirations/_id/index.vue

export default {
  async asyncData({ $axios, params }) {
    const inspiration = await $axios.$get(`/api/v3/inspo/${params.id}`)

    return { inspiration }
  },
}

Things I have tried:

OFK0 commented 3 years ago

I had the same problem, it doesn't make sense but I have come up with a simple solution :)

I've created plugins/axios.js

export default function ({ $axios, $toast, store, redirect }) {
  $axios.onError((error) => {
    // error 
  })

  $axios.onRequest((config) => {
    config.url = '<your url>' + config.url

  })
}

For example when you send Axios request to "categories/list" it will be "https://domain.com/categories/list"

I know it is simple but now it's working 😄

farnabaz commented 3 years ago

Hey, Sorry for the late response, do you mind create reproduction sample using template.nuxtjs.org?

pi0 commented 3 years ago

You can use workaround from @OFK0

imprisoner commented 2 years ago

this helped me https://developpaper.com/connect-econnreused-127-0-0-180-exception-resolution/

in package.json

"config": {
    "nuxt": {
      "host": "0.0.0.0",
      "port": "80"
    }
  }