If we convert SPA application to SSR+SPA when a page is rendered on server the data is loaded from vuex store by dispatching actions that make http calls through axios to api on localhost.
Or that data is need to be loaded from database and some how passed to vue and prevent dispatches of store actions?
In traditional application I will retrieve that data direct from data base and not make get request.
It is normal? This is the way?
Nuxt also use get request and not database queries:
export default {
asyncData({ params, error }) {
return axios
.get(`https://my-api/posts/${params.id}`)
.then(res => {
return { title: res.data.title }
})
.catch(e => {
error({ statusCode: 404, message: 'Post not found' })
})
}
}
I can do that without nuxt in serverPrefetch().
On other hand if I do something like
export default {
asyncData({ req, res }) {
and here if I access database like in node server
(req, res) => {
**select something from database **
return User.findOne({ });
}
}
}
Back end sensitive code will be visible in front end script?!