From e264956831cf2c3635abeda294811a8a8844fde2 Mon Sep 17 00:00:00 2001 From: goynov Date: Fri, 29 Nov 2024 19:13:53 +0200 Subject: [PATCH] manuals, deploy, docs --- .docs/diagram-template/vp/ShortDetails2.xml | 229 ++++++++++++++++++++ .docs/ecosystem.config.cjs | 9 + .docs/server-installation.md | 45 ++++ .env | 3 + .gitignore | 3 +- backend/app/App.js | 1 + backend/app/Config.js | 6 +- backend/app/WebServer.js | 22 +- deploy.bat | 2 + deploy.sh | 8 + vite.config.mjs | 3 + 11 files changed, 310 insertions(+), 21 deletions(-) create mode 100644 .docs/diagram-template/vp/ShortDetails2.xml create mode 100644 .docs/ecosystem.config.cjs create mode 100644 .docs/server-installation.md create mode 100644 .env create mode 100644 deploy.bat create mode 100644 deploy.sh diff --git a/.docs/diagram-template/vp/ShortDetails2.xml b/.docs/diagram-template/vp/ShortDetails2.xml new file mode 100644 index 0000000..c407a20 --- /dev/null +++ b/.docs/diagram-template/vp/ShortDetails2.xml @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + Template Parameters + + + + + + Name + + + Type + + + Default Value + + + + + + + + + + + + + + + + + + + + + + Атрибути + + + + + + Име + + + Описание + + + + + + + + + + + + + + + + + + Enumeration Literals Summary + + + + + + Name + + + Description + + + + + + + + + + + + + + + + + + + Методи + + + + + + Име + + + Описание + + + + + + + + + + + + + + + + + + + Enumeration Literals + + + + + + + + + + Specification + + + + + + + + + + Slots + + + + + = + + + + , + + + + + + + + + + + + + + + + + + + + + + + Chart Relations + + + + + + Code + + + Begin + + + End + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.docs/ecosystem.config.cjs b/.docs/ecosystem.config.cjs new file mode 100644 index 0000000..4af863b --- /dev/null +++ b/.docs/ecosystem.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + apps : [{ + name : "pronature", + script : "/var/node/pronature/backend/main.js", + cwd : "/var/node/pronature/", + instances : 2, + exec_mode : "cluster" + }] + } \ No newline at end of file diff --git a/.docs/server-installation.md b/.docs/server-installation.md new file mode 100644 index 0000000..982c75c --- /dev/null +++ b/.docs/server-installation.md @@ -0,0 +1,45 @@ +# Server and Application Installation +## Services to install +### [Mongo DB Community 8+ ](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/) +> sudo apt-get install gnupg curl +> curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ + sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \ + --dearmor +> echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list +> sudo apt-get update +> sudo apt-get install -y mongodb-org +> sudo systemctl start mongod +> sudo systemctl status mongod +> sudo systemctl enable mongod + +### NodeJS +> curl -fsSL https://fnm.vercel.app/install | bash +> source ~/.bashrc +> fnm use --install-if-missing 22 +> node -v # should print `v22.11.0` +> npm -v # should print `10.9.0` + +### PM2 +> npm install pm2 -g +> pm2 startup + +2. NGINX. Important config - set redirect from http to https. Virtual host config example - [**nginx.`your_dl_name`.conf** ](./nginx.your_dl_name.conf) +3. PM2. Install and enable the process manager for nodejs (after NodeJS and NPM are installed). Config and run using the nonroot user. +4. SPHINX. Install in **/opt/sphinx**. Create a service using config in sphinx.service. Copy to sphinx bin/ folder and configure FTS indexes in [**sphinx.conf**](./sphinx.conf) template. Make sure all paths are available. **/opt/sphinx** should be owned by the nonroot user. + +## Tools to install +1. NodeJS and NPM (currently Node v16, NPM v8) +1. [Mongo DB tools](https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools) +1. Let's Encrypt CertBot, for certificates issuing and renewal. The certificate is installed using the following command: `certbot certonly -d your.server.name`. Use `--nginx` or `--apache` in order to have automatic renewal +1. ffmpeg - for converting video and audio content +1. ghostscript - for creating thumbnails for PDF files +1. OpenSSH Server - to be able to access the server remotely +1. UFW - Firewall, configure to allow access only on 443, 80, and 22 (if possible, only for specific hosts) +1. rsync - for backup +1. fail2ban - to protect from SSH attacks +1. postfix - in order to get CRON jobs notifications +1. mailutils - CRON jobs mail notifications +1. In order to enable web server monitoring you can install and run: + - Linux Dash using this [instruction](https://github.com/afaqurk/linux-dash). You can run it using `pm2 start ecosystem.config.js` (on https://your.server.name/host-monitor/) OR + + - [Netdata](https://learn.netdata.cloud/docs/installing/one-line-installer-for-all-linux-systems) - `wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh --stable-channel` diff --git a/.env b/.env new file mode 100644 index 0000000..758a290 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +NODE_ENV=development +SRV_PORT=3000 +SRV_SSL=1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 85e4037..1e16aa9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .DS_Store node_modules -/dist +/.dist /out +/frontend .docs/out/ /repo diff --git a/backend/app/App.js b/backend/app/App.js index 410907f..0db85af 100644 --- a/backend/app/App.js +++ b/backend/app/App.js @@ -7,6 +7,7 @@ import { fileURLToPath } from 'url'; class App{ constructor(){ this.root = path.resolve(dirname(fileURLToPath(import.meta.url)) + '/../../'); + console.log('App root is set to', this.root); } /** diff --git a/backend/app/Config.js b/backend/app/Config.js index ee43397..3767306 100644 --- a/backend/app/Config.js +++ b/backend/app/Config.js @@ -1,5 +1,5 @@ import path from 'path' - +const pe = process.env; /** * Configuration class */ @@ -54,13 +54,13 @@ class Config{ * @type {boolean} * @memberof SiteOptions */ - ssl: true, + ssl: !!parseInt(pe.SRV_SSL), /** Port to use * @type {Number} * @memberof SiteOptions */ - port: 3000, + port: pe.SRV_PORT, /** * @class Certificate data diff --git a/backend/app/WebServer.js b/backend/app/WebServer.js index 92f1784..c4e4a09 100644 --- a/backend/app/WebServer.js +++ b/backend/app/WebServer.js @@ -73,25 +73,13 @@ class WebServer { * @param {App} app The application instance */ async start(app) { - let indexFile = app.root + '/index.html'; - - let indexFileContent = fs.readFileSync(indexFile, { encoding: 'utf-8' }); - - function index(req, res) { - //res.sendFile(indexFile); - res.send(indexFileContent.replace(/\#NONCE\#/g, res.locals.cspNonce)); - } - - this.xapp.get('/', index); - - // app.config.langs.forEach(l => { - // this.xapp.use('/' + l.code, index); - // }) - - this.xapp.use(express.static(`${this.app.root}/dist/`)); + + this.xapp.use(express.static(`${this.app.root}/frontend/`)); this.xapp.use((req, res, next) => { - if (req.method == 'GET' || req.method == 'POST') { + if (req.method == 'GET'){ + res.sendFile(`${this.app.root}/frontend/index.html`); + }else if (req.method == 'POST') { return res.status(404).end(); } else next(); }); diff --git a/deploy.bat b/deploy.bat new file mode 100644 index 0000000..2b5df82 --- /dev/null +++ b/deploy.bat @@ -0,0 +1,2 @@ +call npm run build +bash -c ./deploy.sh \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..f37b441 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,8 @@ +rm -r ./.dist +mkdir .dist +cp -r backend ./.dist/ +cp -r frontend ./.dist/ +cp package.json ./.dist/ +cp package-lock.json ./.dist/ + +rsync -rv -e 'ssh -p 9922' ./.dist/ pronature@localhost:/var/node/pronature/ \ No newline at end of file diff --git a/vite.config.mjs b/vite.config.mjs index 2ac2333..bf3d59b 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -63,6 +63,9 @@ export default defineConfig({ '.vue', ], }, + build:{ + outDir:'./frontend', + }, server: { watch: { ignored: /repo|3rdparty/