0
votes

I try to build up a ssr project. So I use store in asyncData function as follow

async asyncData({ store, params, req }) {
  if(process.server){
    store.dispatch(...)
    store.commit(...)
    return {...}
  }
}

It works great in client dev environment, it creates new store with new axios client for every request for server side render. But once I put it to lab, a container build up on aws, it goes wired. Request and session were different, but they shared the same store, and axios instance. So that make my data mess up.

lib: "nuxt": "^2.12.2", "axios": "^0.19.2",

========================= update 1 =========================

I got first point, once I build up and run locally, it ran in same result. before script:

"cross-env NODE_ENV=development backpack"

now script:

"cross-env NODE_ENV=production nuxt build"
"cross-env NODE_ENV=production backpack build"
"cross-env NODE_ENV=production node build/main.js"
1
you dont need if(process.server) because asyncData is always on server side - Ifaruki
It does run in client as well, but that's not the point to cause the problem - 鄞阿毛

1 Answers

0
votes

Problem is how I defined for store module.

    // won't share state
    const state = {}
    export default {
      state: () => { return { ...state } }
    }
    // share state
    const state = {}
    export default {
      state:() => state
    }