Reputation: 1481
There are many threads about this question. I tried all but nothing seems to work so I am posting this question. I have done the following way.
store/actions.js
const actions = {
async nuxtServerInit ({ commit, dispatch }, ctx) {
console.log('called nuxtServerInit')
if (ctx.res && ctx.res.locals && ctx.res.locals.user) {
const { allClaims: claims, ...authUser } = ctx.res.locals.user
}
try {
const host = ctx.req.headers.host
// console.log('ctx.req', ctx.req.headers)
console.log('host', host)
const res = await this.$axios.post('/vendors/configuration', { domain: host })
commit('SET_SITE_DATA', res.data.data.site_data)
} catch (err) {
console.error(err)
}
},
}
export default {
...actions
}
store/index.js
import Vuex from 'vuex'
import mutations from './mutations'
import getters from './getters'
import actions from './actions'
import state from './state'
const store = () => {
return new Vuex.Store({
state,
getters,
mutations,
actions
})
}
export default store
store/state.js
export default () => ({
siteData: null,
})
store/mutations.js
const mutations = {
SET_SITE_DATA (state, value) {
state.siteData = {
site_title: value.site_title,
logo: value.logo
}
}
}
export default {
...mutations
}
store/getters.js
const getters = {
siteDetails: state => state.siteData
}
export default {
...getters
}
This is working perfectly in my local. But when I uploaded it to production. it is not working at all. As suggested by other threads I tried mode: universal
, ssr: true
in my nuxt.config.js. But it is not working at all.
I run npm run build
and then pm2 start npm --name "nuxt-project" -- start
I am using pm2 for the production mode.
Even the console is also not printing. Can anyone please help me? Or how to trace it?
Upvotes: 0
Views: 535