Static GitHub Issues

[2445] nuxtServerInit() not respond to Local API URL

prev: Does Nuxt work with Firebase Hosting ?
next: in nested routes parent page data resets

Hello, I've created an issue before, but no one give real solution, and the issue Closed!! check it: https://github.com/nuxt/nuxt.js/issues/2307

generally I'm using AdonisJs and NuxtJs!

this is my nuxtServerInit() function:

 async nuxtServerInit ({ commit }) {
    const response = await axios.get('http://localhost:3333/api/v1/getcounter/')
    return Promise.resolve(commit('increment', response.data))
  },

this code won't work for me, the response status: 204!! but when i change the URL to another API Like this:

 async nuxtServerInit ({ commit }) {
    const response = await axios.get('https://www.random.org/integers/?num=1&min=1&max=2&col=1&base=10&format=plain&rnd=new')
    return Promise.resolve(commit('increment', response.data))
  },

it works and i get the data. but the local API URL works when use it on another Action Function:

 async increment ({ commit }) {
    try {
      const response = await axios.get('http://localhost:3333/api/v1/getcounter/')
      return commit('increment', response.data)
    } catch (e) {
      console.log(e)
    }
  }

this works when use it!!

i have tried to Dispatch the increment when component mounted() or beforeCreated()

mounted () {
      this.$store.dispatch('increment')
    },

but when loading the page:

it shows the value from nuxtServerInit(): 1. if the url is Local (it means nuxtServerInit() won't work) the result is: null or NAN. 2. else if the URL (like random.org): it shows the value 1 or 2.

then in moment it shows the value of dispatch. i have searched a lot, some one said this is the solution? https://github.com/nuxt-community/express-template/blob/master/protected-ssr-api.md

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2121">#c2121</a>)</em></sub></div>