P
P
pgs2021-04-13 21:02:55
Node.js
pgs, 2021-04-13 21:02:55

Development: server - node.js, client - vue.js. How to combine?

Good afternoon!
Problem:
there is a server on node.js + express that sends a URL (like: '/api/users/all') from a json database with data that needs to be taken to vue (project created via vue-cli) via fetch() or axios().
Development is carried out on the local computer.
The server is running on port 3000, the client is on 8080.

If I access the server from the client using the server:3000/api/users/all link , then a CORS error occurs (which can be solved by allowing cross server requests).

If I write the internal URL '/api/users/all' in the client, which I access in fetch(), I throw the result of the request into data() on vue in the client and then I form the bundle via "npm run build", after which I throw the bundle into the public folder of the server on Node.js - then everything works fine, but there is an inconvenience in terms of development, since for any change in the client, you need to form a deploy bundle and copy it manually to the public folder on the server.

What approaches do you use in this case and is it correct at all?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
low molecular macro, 2021-04-13
@pgs

If I access the server from the client using the link server:3000/api/users/all, then a CORS error occurs (which can be solved by allowing cross server requests).

npm i cors
If I write the internal URL '/api/users/all' in the client, which I access in fetch(), I throw the result of the request into data() on vue in the client and then I form the bundle via "npm run build", after which I throw the bundle into the public folder of the server on Node.js - then everything works fine, but there is an inconvenience in terms of development, since for any change in the client, you need to form a deploy bundle and copy it manually to the public folder on the server.

Didn't catch the idea, but create 2 folders - server and client

V
Vitaly, 2021-04-13
@vshvydky

nginx - front bundle statics, api proxy pass to node instance (upstream)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question