Monday, 14 October 2019

React Frontend Node backend server.js on Nginx

Hello All,I have made a website that has a front-end on reactjs and backend in node.js. The front end does a fetch request at the urls to connect to the server.js that then responds to the requests. Everything runs fins in my local machine. The front-end sends the requests, the backend responds to the requests and data is saved on the postgress database. This work is for my school project and I have been given access to the school server that is running nginx. I have hosted the front-end of my app on nginx at a certain url. How would I go on about setting up the node server.js. Would I just do an npm start and leave the node server process running in the terminal instead of running it on nginx?Since I cannot share my exact code, this should give a rough idea:FrontEnd ReactJS:class MyApp extends....{fetch("localhost:3000/getInfo"........);fetch("localhost:3000/pictureUrl".....);}backend node.js:app.post('/getInfo', (req,res.......................);app.get('/pictureUrl', (req,res.........................);nginx config file:​server {listen 80;listen [::]:80;root /var/www/domain.com/html/build/;index index.html index.php index.htm index.nginx-debian.html;server_name domain.com;​location / { try\_files $uri /index.html; }}​So, when I visit the domain.com the front end is working. Now I want the backend to be running 24/7 so that the frontend can communicate with the backend and the database postgres.Thanks any help is greatly appreciated!

Submitted October 15, 2019 at 06:32AM by LittleHulk99

No comments:

Post a Comment