Image
Ruthger Idema
2019-03-14 18:23:12 / Ruthger Idema

Running Nuxt & Express on a Forge provisioned server

For Ide.ma I'm using the Nuxt Server Side Rendering option (with Express JS), but as soon as I wanted to deploy the application I found out that this doesn't work out of the box.

In order to get Nginx proxying to Node I had to replace the 'location / {}' function with the following:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.org/server;
location / {
expires epoch;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:3000;
}

You can use PM2 for keeping Express alive. For this application I've set up a simple PM2 instance who watches the server. 


I use the following Forge deploy script to deploy without downtime:
# stop script on error signal
set -e
# remove old deployment folders
if [ -d "/home/forge/deploy" ]; then
rm -R /home/forge/deploy
fi
if [ -d "/home/forge/backup" ]; then
rm -R /home/forge/backup
fi
cp -R /home/forge/ide.ma /home/forge/deploy
# Update
cd /home/forge/deploy
git pull origin master
npm run build
# Switch
mv /home/forge/ide.ma /home/forge/backup
mv /home/forge/deploy /home/forge/ide.ma
cd /home/forge/ide.ma
pm2 reload Ide.ma

© 2019 Ide.ma | Ruthger Idema