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

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

Closed
bryceandy opened this issue Nov 6, 2020 · 4 comments

Comments

@bryceandy
Copy link

Nuxt version 2.14.7

Axios module 5.12.2

Problem: (Occurring only in production)

  • When using axios module in asyncData on a page with middleware and directory structure /dirName/fileName.vue, the request goes to correct baseURL.
  • When doing the same request on a page without middleware and regardless of directory structure, example /dirName/_id/index.vue the error is shown as in the title
  • When I hard-code the baseURL in the config, it works, but process.env.SOME_VARIABLE does not work on the previous situation

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:

  • I changed
modules: [
    '@nuxtjs/axios',
  ],
axios: {
    baseURL: process.env.API_URL,
    headers: {
      common: {
        Accept: 'application/json',
      },
    },
  },

into

modules: [
    ['@nuxtjs/axios', { baseURL: process.env.API_URL }],
  ],
axios: {
    headers: {
      common: {
        Accept: 'application/json',
      },
    },
  },

Nothing changed. The only fix I have now is to hard code the baseURL

@OFK0
Copy link

OFK0 commented Dec 16, 2020

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 😄

Copy link
Member

farnabaz commented Feb 8, 2021

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

@pi0
Copy link
Member

pi0 commented Oct 25, 2021

You can use workaround from @OFK0

@imprisoner
Copy link

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"
    }
  }

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

No branches or pull requests

5 participants