Answer the question
In order to leave comments, you need to log in
Is it possible to host the Nuxt.js backend code and API backend on the same server?
Good evening everyone. I deployed Nuxt.js for the first time, went to 'server/index.js', the question arose - is it possible to somehow import the API, the logic of working with the database, and so on into this index, which, in theory, should spin on a separate back? When installing Nuxt, I chose Express as the back-framework, tried placing the following code in 'server/index.js' and it worked.
app.get('/apitest', function (req, res) {
res.send('Hello World!')
})
Answer the question
In order to leave comments, you need to log in
No one forbids, this is a Nuxt.js programmatic call . Anything above the render middleware can be used to build logic. The logic of Nuxt.js is based on the fact that we make requests to the server whether it is SSR or SPA. But this approach has significant disadvantages:
1. If we change the backend, then Nuxt.js itself will be restarted (which obviously loses its convenience in development).
2. When moving to two different servers, we will need to split this code first.
3. If there is an increased load on the rendering of the fronted, then the backend will also suffer from this due to the peculiarities of Node.js.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question