M
M
Maxim Noverin2019-05-08 22:43:38
Vue.js
Maxim Noverin, 2019-05-08 22:43:38

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!')
})

With a get request via postman, the response was expected and correct. Actually, the question arises: is it possible to write the logic of interaction with the database somewhere nearby, describe the api and import it into 'server/index.js'. If this is technically feasible, is it worth doing this, or is it still better to have a separate backing for the api?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2019-05-09
@senover

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 question

Ask a Question

731 491 924 answers to any question