diff --git a/deployment/README.md b/deployment/README.md index e3440094a8..523cc57dbb 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -62,6 +62,10 @@ Configure nginx: cp -f deployment/nginx/default.conf /etc/nginx/http.d/default.conf # adjust the nginx config accordingly vi /etc/nginx/http.d/default.conf +# frontend nginx config +cp deployment/nginx/frontend.conf /etc/nginx/http.d/frontend.conf +# adjust the frontend nginx config accordingly +vi /etc/nginx/http.d/frontend.conf # note: replace log paths according to your installation directory service nginx restart ``` diff --git a/deployment/deploy.sh b/deployment/deploy.sh index d07c61a569..e771869470 100755 --- a/deployment/deploy.sh +++ b/deployment/deploy.sh @@ -32,16 +32,20 @@ exec 3>&1 1>>${LOG_FILE} 2>&1 2>>${LOG_ERROR_FILE} export NODE_ENV=production # Backend & Database Migration - $SCRIPT_DIR/build.backend.sh - $SCRIPT_DIR/migrate.database.sh - $SCRIPT_DIR/start.backend.sh + $SCRIPT_DIR/scripts/build.backend.sh + $SCRIPT_DIR/scripts/migrate.database.sh + $SCRIPT_DIR/scripts/start.backend.sh + + # Frontend + $SCRIPT_DIR/scripts/build.frontend.sh + $SCRIPT_DIR/scripts/start.frontend.sh # Presenter - $SCRIPT_DIR/build.presenter.sh - $SCRIPT_DIR/start.presenter.sh + $SCRIPT_DIR/scripts/build.presenter.sh + $SCRIPT_DIR/scripts/start.presenter.sh # Docs - $SCRIPT_DIR/build.docs.sh + $SCRIPT_DIR/scripts/build.docs.sh # restore node env NODE_ENV=$BACKUP_NODE_ENV diff --git a/deployment/nginx/default.conf b/deployment/nginx/default.conf index 30a61f450a..c9bf9d6890 100644 --- a/deployment/nginx/default.conf +++ b/deployment/nginx/default.conf @@ -12,7 +12,7 @@ server { proxy_buffers 4 512k; proxy_buffer_size 256k; - proxy_pass http://127.0.0.1:3000/; + proxy_pass http://127.0.0.1:3001/; proxy_redirect off; access_log /var/www/localhost/htdocs/dreammall.earth/log/nginx.access.presenter.log combined; diff --git a/deployment/nginx/frontend.conf b/deployment/nginx/frontend.conf new file mode 100644 index 0000000000..96e53bda8e --- /dev/null +++ b/deployment/nginx/frontend.conf @@ -0,0 +1,21 @@ +server { + listen 8080 default_server; + listen [::]:8080 default_server; + + location / { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_buffers 4 512k; + proxy_buffer_size 256k; + + proxy_pass http://127.0.0.1:3000/; + proxy_redirect off; + + access_log /var/www/localhost/htdocs/dreammall.earth/log/nginx.access.frontend.log combined; + error_log /var/www/localhost/htdocs/dreammall.earth/log/nginx.error.frontend.log warn; + } +} diff --git a/deployment/build.backend.sh b/deployment/scripts/build.backend.sh similarity index 86% rename from deployment/build.backend.sh rename to deployment/scripts/build.backend.sh index 290fb810ef..1a8ed02e31 100755 --- a/deployment/build.backend.sh +++ b/deployment/scripts/build.backend.sh @@ -3,7 +3,7 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) -PROJECT_ROOT=$SCRIPT_DIR/../backend +PROJECT_ROOT=$SCRIPT_DIR/../../backend BUILD_DIR=$PROJECT_ROOT/build # Build the project diff --git a/deployment/build.docs.sh b/deployment/scripts/build.docs.sh similarity index 90% rename from deployment/build.docs.sh rename to deployment/scripts/build.docs.sh index 0e30d855dd..801b10771c 100755 --- a/deployment/build.docs.sh +++ b/deployment/scripts/build.docs.sh @@ -3,7 +3,7 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) -PROJECT_ROOT=$SCRIPT_DIR/.. +PROJECT_ROOT=$SCRIPT_DIR/../.. BUILD_DIR=$PROJECT_ROOT/build/docs # Build the project diff --git a/deployment/scripts/build.frontend.sh b/deployment/scripts/build.frontend.sh new file mode 100755 index 0000000000..40fa1b968d --- /dev/null +++ b/deployment/scripts/build.frontend.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Find current directory & configure paths +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) +PROJECT_ROOT=$SCRIPT_DIR/../../frontend +BUILD_DIR=$PROJECT_ROOT/build + +# Build the project +cd $PROJECT_ROOT +rm -R $BUILD_DIR +npm install --include=dev +npm run build diff --git a/deployment/build.presenter.sh b/deployment/scripts/build.presenter.sh similarity index 85% rename from deployment/build.presenter.sh rename to deployment/scripts/build.presenter.sh index 0fd364d395..a4b7ca049f 100755 --- a/deployment/build.presenter.sh +++ b/deployment/scripts/build.presenter.sh @@ -3,7 +3,7 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) -PROJECT_ROOT=$SCRIPT_DIR/../presenter +PROJECT_ROOT=$SCRIPT_DIR/../../presenter BUILD_DIR=$PROJECT_ROOT/build # Build the project diff --git a/deployment/migrate.database.sh b/deployment/scripts/migrate.database.sh similarity index 82% rename from deployment/migrate.database.sh rename to deployment/scripts/migrate.database.sh index e76b185de3..24b029db17 100755 --- a/deployment/migrate.database.sh +++ b/deployment/scripts/migrate.database.sh @@ -3,7 +3,7 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) SCRIPT_DIR=$(dirname $SCRIPT_PATH) -PROJECT_ROOT=$SCRIPT_DIR/../backend +PROJECT_ROOT=$SCRIPT_DIR/../../backend # Build the project cd $PROJECT_ROOT diff --git a/deployment/start.backend.sh b/deployment/scripts/start.backend.sh similarity index 63% rename from deployment/start.backend.sh rename to deployment/scripts/start.backend.sh index 6993f6fb15..d31046ddfa 100755 --- a/deployment/start.backend.sh +++ b/deployment/scripts/start.backend.sh @@ -2,9 +2,10 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) -SCRIPT_DIR=$(dirname $SCRIPT_PATH)/../backend -LOG_FILE=$SCRIPT_DIR/../log/$(date +"%Y-%m-%d_%T")_pm2.backend.log +SCRIPT_DIR=$(dirname $SCRIPT_PATH) +PROJECT_ROOT=$SCRIPT_DIR/../../backend +LOG_FILE=$SCRIPT_DIR/../../log/$(date +"%Y-%m-%d_%T")_pm2.backend.log -cd $SCRIPT_DIR +cd $PROJECT_ROOT NODE_ENV=production TZ=UTC TS_NODE_BASEURL=./build pm2 start --name backend "node -r tsconfig-paths/register build/src/index.js" -l $LOG_FILE --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save diff --git a/deployment/scripts/start.frontend.sh b/deployment/scripts/start.frontend.sh new file mode 100755 index 0000000000..352d0cbb78 --- /dev/null +++ b/deployment/scripts/start.frontend.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Find current directory & configure paths +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) +PROJECT_ROOT=$SCRIPT_DIR/../../frontend +LOG_FILE=$SCRIPT_DIR/../../log/$(date +"%Y-%m-%d_%T")_pm2.frontend.log + +cd $PROJECT_ROOT +export PORT=3000 +pm2 start --name frontend "build/index.cjs" -l $LOG_FILE --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' +pm2 save \ No newline at end of file diff --git a/deployment/start.presenter.sh b/deployment/scripts/start.presenter.sh similarity index 51% rename from deployment/start.presenter.sh rename to deployment/scripts/start.presenter.sh index 8bce8210a1..bb58b506f3 100755 --- a/deployment/start.presenter.sh +++ b/deployment/scripts/start.presenter.sh @@ -2,9 +2,11 @@ # Find current directory & configure paths SCRIPT_PATH=$(realpath $0) -SCRIPT_DIR=$(dirname $SCRIPT_PATH)/../presenter -LOG_FILE=$SCRIPT_DIR/../log/$(date +"%Y-%m-%d_%T")_pm2.presenter.log +SCRIPT_DIR=$(dirname $SCRIPT_PATH) +PROJECT_ROOT=$SCRIPT_DIR/../../presenter +LOG_FILE=$SCRIPT_DIR/../../log/$(date +"%Y-%m-%d_%T")_pm2.presenter.log -cd $SCRIPT_DIR +cd $PROJECT_ROOT +export PORT=3001 pm2 start --name presenter "build/index.cjs" -l $LOG_FILE --log-date-format 'YYYY-MM-DD HH:mm:ss.SSS' pm2 save \ No newline at end of file