Axios-module: 404? What might be wrong here?

Created on 15 Nov 2017  路  9Comments  路  Source: nuxt-community/axios-module

Hi,

Trying out the module. I have put my json in an /api folder in the project root.
code looks like this and the request url seems correct.

Error:
GET http://localhost:3000/api/studio/index.json 404 (Not Found)

Code:

  async asyncData ({ app }) {
    let { data } = await app.$axios.$get('/studio/index.json')
    return { content: data }
  },

Any idea what might be wrong?

This question is available on Nuxt.js community (#c53)

Most helpful comment

well, it seems that you should npm run dev and keep that running, then npm run generate.
my version @nuxtjs/axios: 5.0.1

All 9 comments

@jesperlandberg putting your .json file in the api folder doesn't mean the endpoint exists. Until u make it.

@BruceHem is correct. If what you need is just serving static json content, you can create static/api/studio/index.json file and it will work :)

@BruceHem okey cool. Will try that!

@BruceHem @pi0 worked better! Now the data is fetched both on route changee and page refresh. However, when i run nuxt generate (npm run generate) I get the following error, any idea what is the reason for this?

==== Error report ====
Route: '/studio'
Error: connect ECONNREFUSED 127.0.0.1:3000
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)

In my nuxt.config.js I have this:

  modules: [
    '@nuxtjs/axios'
  ],
  axios: {
    baseUrl: process.env.BASE_URL || 'http://localhost:3000'
  },

Honestly, I don't know what that could be. I never used generate at all.

@BruceHem might it be something about it trying to fetch data from my localhost? That isn't running because I'm "exiting" dev mode when running generate?

Unfrtounaly nuxt generate doesn't supports serverMiddleware. Upgrading to 5.0.0 may help to resolve issues. If still having problems, please reopen.

well, it seems that you should npm run dev and keep that running, then npm run generate.
my version @nuxtjs/axios: 5.0.1

@levy9527 @jesperlandberg Hello, I also encountered the problem mentioned above. npm run generate time report the following error, may I ask what can be solved, thank you

Error: connect ECONNREFUSED 127.0.0.1:3000
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cawa-93 picture cawa-93  路  4Comments

gammpamm picture gammpamm  路  4Comments

ealves-pt picture ealves-pt  路  3Comments

kaboume picture kaboume  路  4Comments

mclighter picture mclighter  路  3Comments