Navigate to the 'back' folder
cd back
Create credentials file
nano key.json
Add the following mongodb credentials
{
"username" : "<mongodb username>",
"password" : "<mongodb password>",
"cluster" : "<mongodb cluster>",
"secret" : "<some really long, randomly generated string with numbers and symbols>"
}
Install node modules
npm install
Run the server
node server.js
Edit the default config file
sudo nano /etc/nginx/sites-enabled/default
Replace its contents with the following
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Restart nginx
sudo systemctl restart nginx
Install pm2
sudo npm install -g pm2
Start server
pm2 start server.js
Get startup command
pm2 startup systemd
Copy and paste the output of the last command
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
Save current pm2 state (running server.js)
pm2 save
Navigate to the 'front' folder
cd front
Install node modules
npm install
Build the React project for production
npm run build
Use https://www.sslforfree.com/ to generate keys
server {
listen 80;
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}