"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
<!--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/c1336">#c1336</a>)</em></sub></div>--------------------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