0

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?

Dhara
  • 1,431
  • 4
  • 29
  • 47
  • You only have either `"static"` or `"server"` for "target" and `true` or `false` for `ssr`. `mode` is deprecated. Also, what commands did you tried to build it locally? Does the issue still happen when you `yarn start` it locally? Did you checked some env keys? – kissu Sep 24 '21 at 21:28
  • Lastly, if you ask the thing to run on the server, check back to your terminal to see it therefore rather than on browser side. – kissu Sep 24 '21 at 21:30
  • @kissu I am running npm run dev for the local and for the production npm run build and using pm2 for the running. – Dhara Sep 27 '21 at 06:45
  • On the server if I run npm run dev then it is working. – Dhara Sep 27 '21 at 06:46
  • What can I do then? – Dhara Sep 27 '21 at 07:56
  • Fix the actual issue by checking logs somewhere and double checking your configuration mostly. – kissu Sep 27 '21 at 08:28
  • 1
    I know it may look silly , but have you tried using integrated vuex file? (no seperated state,mutation,getter,actions , just one index.js file with all four) ?? I have been working with nuxt nearly two years and have built my app on many server (nginx + pm2) and it works fine! also be careful of pm2 , sometime it wont stop properly with you gonna run build/start again – Mojtaba Barari Sep 27 '21 at 13:29
  • @MojtabaBarari no reason for it not working without modules. – kissu Sep 27 '21 at 14:40
  • @kissu , I know , but you definitely must have experience these illogical behaviours ! XD . I have many experience with these situations where two identical piece of codes behave differently XD – Mojtaba Barari Sep 28 '21 at 06:32
  • @MojtabaBarari I haven't tried with using index.js file. But I will definitely try. Because I tried all other option in nuxt.config.js but not working at all. – Dhara Sep 28 '21 at 07:53

0 Answers0