Home

Issue: 1501

in nuxtServerInit when i use axios to post body first is ok and second the body is nothing?

[issue link]
"axios": "^0.16.2",
 "nuxt": "^1.0.0-rc6",
 "qs": "^6.5.0"

store/index.js


export const actions = {
  async nuxtServerInit ({state, commit, dispatch}, {app, req, res}) {
    try {
      console.log('--------------------nuxtServerInit:')

      const api_token_ts = await app.api.post(`/share/auth/apiToken`, { path: 'apps/99alive', username: 'aaaa' })
      const apiToken = await app.api(`/apps/99alive/apiToken`)
      console.log(apiToken)

      let urls = [
        app.api(`/share/keys.json`),
        app.api(`/share/district/cities/,_id name first_letter hot`),
        ...state.tpa._searchDimensionIds.map(o => app.api(`/share/dictionary/${o}/pair`))
      ]
      // console.log('urls: ', urls)
      await axios.all(urls).then(axios.spread(($keys, cities, ...searchDimensions) => {
        commit(indexTypes.SET_$KEYS, $keys)
        commit(indexTypes.SET_CITIES, cities)
        commit(tpaPrefix + '/'+ tpaTypes.SET_SEARCH_DIMENSIONS, searchDimensions)
      }))

      let token  = parseCookie(req.headers.cookie, 'token')
      let signin_ts  = parseCookie(req.headers.cookie, 'signin_ts')
      console.log('token:', token, signin_ts)
      if (token && signin_ts) {
        await dispatch(`${uaPrefix}/signinByToken`, {token, signin_ts})
      }

    } catch (e) {
      // console.error('Error on [nuxtServerInit] action.', e) // eslint-disable-line no-console
    }
  },
  switchCity ({state, commit}, cityId) {
    commit(indexTypes.SET_CITY, state._cities.find(c => c._id === cityId))
    return Promise.resolve()
  }
}

first time invoke the log:

nuxt:render Rendering url /login +27s
--------------------nuxtServerInit:
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:path=apps%2F99alive&username=aaaa

it’s ok
then when i use F5

--------------------nuxtServerInit:
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:path=apps%2F99alive&username=aaaa
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:

it seems invoke twice,and the second invoke with body empty
now, i refreshed by F5 agian and the log:

--------------------nuxtServerInit:
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:path=apps%2F99alive&username=aaaa
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:
CORS:post->http://192.168.10.194:3003/apis/share/auth/apiToken
data:

it invoke three times!!!
what’s going on
@alexchopin @pi0

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