Compare commits

..

3 Commits

Author SHA1 Message Date
marco370
51a2eec68b Add local authentication for external deployments
Introduce a local authentication system using Passport.js for deployments outside of Replit, including session management and a default admin user setup.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/EAVbbe1
2025-10-16 16:43:55 +00:00
marco370
6924345aa8 Update server and deployment scripts for improved stability
Update REPLIT_DOMAINS, package.json scripts, .env variables, and deploy.sh to include dev dependencies and ensure correct database schema synchronization.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/AwjfjCW
2025-10-16 16:34:19 +00:00
marco370
6194b2cc7b Improve deployment script to fix build errors and dependency issues
Update deploy/deploy.sh to resolve 'Cannot find module' error during Vite build and address npm audit warnings for improved deployment stability.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/AwjfjCW
2025-10-16 16:29:53 +00:00
6 changed files with 732 additions and 8 deletions

View File

@ -19,6 +19,10 @@ externalPort = 80
localPort = 33035
externalPort = 3001
[[ports]]
localPort = 36465
externalPort = 3003
[[ports]]
localPort = 41343
externalPort = 3000

View File

@ -0,0 +1,185 @@
bash deploy/deploy.sh
🚀 Deployment VigilanzaTurni - Thu Oct 16 11:58:04 EDT 2025
📥 Pull ultime modifiche da GitLab...
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
💾 Backup database pre-deployment...
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_115804.sql
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_115804.sql.gz
🧹 Backup vecchi eliminati (retention: 30 giorni)
📥 Installazione dipendenze (include devDependencies)...
added 399 packages, and audited 400 packages in 12s
57 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
🏗️ Build frontend Vite...
> rest-express@1.0.0 build
> node node_modules/vite/bin/vite.js build && node_modules/.bin/esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
node:internal/modules/cjs/loader:1215
throw err;
^
Error: Cannot find module '/var/www/vigilanza-turni/node_modules/vite/bin/vite.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1212:15)
at Module._load (node:internal/modules/cjs/loader:1043:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:164:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v20.19.2
[root@localhost vigilanza-turni]# nano deploy/deploy.sh
[root@localhost vigilanza-turni]# bash deploy/deploy.sh
🚀 Deployment VigilanzaTurni - Thu Oct 16 12:01:24 EDT 2025
📥 Pull ultime modifiche da GitLab...
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
💾 Backup database pre-deployment...
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_120124.sql
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_120124.sql.gz
🧹 Backup vecchi eliminati (retention: 30 giorni)
📥 Installazione dipendenze (include devDependencies)...
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported
added 521 packages, and audited 522 packages in 12s
74 packages are looking for funding
run `npm fund` for details
2 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
🏗️ Build frontend Vite...
> rest-express@1.0.0 build
> node node_modules/vite/bin/vite.js build && node_modules/.bin/esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
vite v6.4.0 building for production...
A PostCSS plugin did not pass the `from` option to `postcss.parse`. This may cause imported assets to be incorrectly
transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue.
✓ 2683 modules transformed.
../dist/public/index.html 1.49 kB │ gzip: 0.63 kB
../dist/public/assets/index-DqscHyOA.css 75.10 kB │ gzip: 12.16 kB
../dist/public/assets/index-VRh79lEQ.js 597.11 kB │ gzip: 175.56 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 9.75s
dist/index.js 56.6kb
⚡ Done in 15ms
🗄️ Verifica database schema...
> rest-express@1.0.0 db:push
> node node_modules/drizzle-kit/bin.cjs push
node:internal/modules/cjs/loader:1215
throw err;
^
Error: Cannot find module '/var/www/vigilanza-turni/node_modules/drizzle-kit/bin.cjs'
at Module._resolveFilename (node:internal/modules/cjs/loader:1212:15)
at Module._load (node:internal/modules/cjs/loader:1043:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:164:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v20.19.2
⚠️ Schema push skipped (database già aggiornato)
🔍 Usando PM2: /usr/local/bin/pm2
🔄 Restart applicazione...
[PM2] Applying action deleteProcessId on app [vigilanza-turni](ids: [ 0 ])
[PM2] [vigilanza-turni](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 0 │ online │ 0% │ 5.4mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Saving current process list...
[PM2] Successfully saved in /root/.pm2/dump.pm2
🏥 Health check...
✅ Deployment completato con successo!
[TAILING] Tailing last 20 lines for [vigilanza-turni] process (change the value with --lines option)
/root/.pm2/logs/vigilanza-turni-error.log last 20 lines:
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
0|vigilanz | file:///var/www/vigilanza-turni/dist/index.js:821
0|vigilanz | throw new Error("Environment variable REPLIT_DOMAINS not provided");
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
/root/.pm2/logs/vigilanza-turni-out.log last 20 lines:
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
📊 Status PM2:
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 4 │ online │ 0% │ 66.1mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
📈 Ultimi backup disponibili:
-rw-r--r-- 1 root root 3.4K Oct 16 12:01 /var/backups/vigilanza-turni/backup_20251016_120124.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:58 /var/backups/vigilanza-turni/backup_20251016_115804.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:56 /var/backups/vigilanza-turni/backup_20251016_115644.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:55 /var/backups/vigilanza-turni/backup_20251016_115524.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:52 /var/backups/vigilanza-turni/backup_20251016_115244.sql.gz
🌐 Applicazione disponibile su: https://vt.alfacom.it

View File

@ -0,0 +1,185 @@
bash deploy/deploy.sh
🚀 Deployment VigilanzaTurni - Thu Oct 16 11:58:04 EDT 2025
📥 Pull ultime modifiche da GitLab...
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
💾 Backup database pre-deployment...
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_115804.sql
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_115804.sql.gz
🧹 Backup vecchi eliminati (retention: 30 giorni)
📥 Installazione dipendenze (include devDependencies)...
added 399 packages, and audited 400 packages in 12s
57 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
🏗️ Build frontend Vite...
> rest-express@1.0.0 build
> node node_modules/vite/bin/vite.js build && node_modules/.bin/esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
node:internal/modules/cjs/loader:1215
throw err;
^
Error: Cannot find module '/var/www/vigilanza-turni/node_modules/vite/bin/vite.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1212:15)
at Module._load (node:internal/modules/cjs/loader:1043:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:164:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v20.19.2
[root@localhost vigilanza-turni]# nano deploy/deploy.sh
[root@localhost vigilanza-turni]# bash deploy/deploy.sh
🚀 Deployment VigilanzaTurni - Thu Oct 16 12:01:24 EDT 2025
📥 Pull ultime modifiche da GitLab...
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
💾 Backup database pre-deployment...
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_120124.sql
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_120124.sql.gz
🧹 Backup vecchi eliminati (retention: 30 giorni)
📥 Installazione dipendenze (include devDependencies)...
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported
added 521 packages, and audited 522 packages in 12s
74 packages are looking for funding
run `npm fund` for details
2 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
🏗️ Build frontend Vite...
> rest-express@1.0.0 build
> node node_modules/vite/bin/vite.js build && node_modules/.bin/esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
vite v6.4.0 building for production...
A PostCSS plugin did not pass the `from` option to `postcss.parse`. This may cause imported assets to be incorrectly
transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue.
✓ 2683 modules transformed.
../dist/public/index.html 1.49 kB │ gzip: 0.63 kB
../dist/public/assets/index-DqscHyOA.css 75.10 kB │ gzip: 12.16 kB
../dist/public/assets/index-VRh79lEQ.js 597.11 kB │ gzip: 175.56 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 9.75s
dist/index.js 56.6kb
⚡ Done in 15ms
🗄️ Verifica database schema...
> rest-express@1.0.0 db:push
> node node_modules/drizzle-kit/bin.cjs push
node:internal/modules/cjs/loader:1215
throw err;
^
Error: Cannot find module '/var/www/vigilanza-turni/node_modules/drizzle-kit/bin.cjs'
at Module._resolveFilename (node:internal/modules/cjs/loader:1212:15)
at Module._load (node:internal/modules/cjs/loader:1043:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:164:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v20.19.2
⚠️ Schema push skipped (database già aggiornato)
🔍 Usando PM2: /usr/local/bin/pm2
🔄 Restart applicazione...
[PM2] Applying action deleteProcessId on app [vigilanza-turni](ids: [ 0 ])
[PM2] [vigilanza-turni](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 0 │ online │ 0% │ 5.4mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Saving current process list...
[PM2] Successfully saved in /root/.pm2/dump.pm2
🏥 Health check...
✅ Deployment completato con successo!
[TAILING] Tailing last 20 lines for [vigilanza-turni] process (change the value with --lines option)
/root/.pm2/logs/vigilanza-turni-error.log last 20 lines:
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
0|vigilanz | file:///var/www/vigilanza-turni/dist/index.js:821
0|vigilanz | throw new Error("Environment variable REPLIT_DOMAINS not provided");
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
/root/.pm2/logs/vigilanza-turni-out.log last 20 lines:
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
📊 Status PM2:
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 4 │ online │ 0% │ 66.1mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
📈 Ultimi backup disponibili:
-rw-r--r-- 1 root root 3.4K Oct 16 12:01 /var/backups/vigilanza-turni/backup_20251016_120124.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:58 /var/backups/vigilanza-turni/backup_20251016_115804.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:56 /var/backups/vigilanza-turni/backup_20251016_115644.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:55 /var/backups/vigilanza-turni/backup_20251016_115524.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:52 /var/backups/vigilanza-turni/backup_20251016_115244.sql.gz
🌐 Applicazione disponibile su: https://vt.alfacom.it

View File

@ -0,0 +1,169 @@
cd /var/www/vigilanza-turni
[root@localhost vigilanza-turni]# git pull origin main
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
[root@localhost vigilanza-turni]# grep "REPLIT_DOMAINS =" server/replitAuth.ts
const REPLIT_DOMAINS = process.env.REPLIT_DOMAINS || process.env.DOMAIN || "vt.alfacom.it";
[root@localhost vigilanza-turni]# bash fix-server.sh
 Fix Deployment Server - vt.alfacom.it
==========================================
 Step 1: Aggiornamento package.json scripts...
 Step 2: Verifica .env...
 Step 3: Verifica deploy.sh...
✅ deploy.sh già configurato correttamente
✅ Fix completato!
 Riepilogo modifiche:
✓ package.json scripts aggiornati
✓ .env con DOMAIN e ISSUER_URL
✓ deploy.sh usa npm ci --include=dev
 Esegui deployment con:
bash deploy/deploy.sh
[root@localhost vigilanza-turni]# bash deploy/deploy.sh
 Deployment VigilanzaTurni - Thu Oct 16 12:30:49 EDT 2025
 Pull ultime modifiche da GitLab...
From https://git.alfacom.it/marco/VigilanzaTurni
* branch main -> FETCH_HEAD
Already up to date.
 Backup database pre-deployment...
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_123049.sql
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_123049.sql.gz
粒 Backup vecchi eliminati (retention: 30 giorni)
 Installazione dipendenze (include devDependencies)...
npm warn deprecated @esbuild-kit/esm-loader@2.6.5: Merged into tsx: https://tsx.is
npm warn deprecated @esbuild-kit/core-utils@3.3.2: Merged into tsx: https://tsx.is
added 496 packages, and audited 497 packages in 12s
67 packages are looking for funding
run `npm fund` for details
8 vulnerabilities (3 low, 5 moderate)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
️ Build frontend Vite...
> rest-express@1.0.0 build
> vite build && esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
vite v5.4.20 building for production...
transforming (3) src/main.tsxBrowserslist: browsers data (caniuse-lite) is 12 months old. Please run:
npx update-browserslist-db@latest
Why you should do it regularly: https://github.com/browserslist/update-db#readme
transforming (4) src/App.tsx
A PostCSS plugin did not pass the `from` option to `postcss.parse`. This may cause imported assets to be incorrectly
transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue.
✓ 2673 modules transformed.
../dist/public/index.html 1.49 kB │ gzip: 0.63 kB
../dist/public/assets/index-DdJrKUWT.css 75.43 kB │ gzip: 12.17 kB
../dist/public/assets/index-C9iY8fDP.js 590.69 kB │ gzip: 173.23 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 8.78s
dist/index.js 56.6kb
⚡ Done in 23ms
️ Verifica database schema...
> rest-express@1.0.0 db:push
> drizzle-kit push --force || drizzle-kit push || echo 'DB schema sync skipped'
No config path provided, using default 'drizzle.config.ts'
Reading config file '/var/www/vigilanza-turni/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...
[i] No changes detected
 Usando PM2: /usr/local/bin/pm2
 Restart applicazione...
[PM2] Applying action deleteProcessId on app [vigilanza-turni](ids: [ 0 ])
[PM2] [vigilanza-turni](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 0 │ online │ 0% │ 5.3mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2] Saving current process list...
[PM2] Successfully saved in /root/.pm2/dump.pm2
 Health check...
✅ Deployment completato con successo!
[TAILING] Tailing last 20 lines for [vigilanza-turni] process (change the value with --lines option)
/root/.pm2/logs/vigilanza-turni-error.log last 20 lines:
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
0|vigilanz | file:///var/www/vigilanza-turni/dist/index.js:821
0|vigilanz | throw new Error("Environment variable REPLIT_DOMAINS not provided");
0|vigilanz | ^
0|vigilanz |
0|vigilanz | Error: Environment variable REPLIT_DOMAINS not provided
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:821:9
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
0|vigilanz |
0|vigilanz | Node.js v20.19.2
/root/.pm2/logs/vigilanza-turni-out.log last 20 lines:
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz | 12:26:05 PM [express] serving on port 5000
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz | 12:26:08 PM [express] serving on port 5000
0|vigilanz |
0|vigilanz | > rest-express@1.0.0 start
0|vigilanz | > NODE_ENV=production node dist/index.js
0|vigilanz |
0|vigilanz | 12:31:17 PM [express] serving on port 5000
 Status PM2:
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ vigilanza-turni │ fork │ 0 │ online │ 0% │ 65.7mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
 Ultimi backup disponibili:
-rw-r--r-- 1 root root 3.4K Oct 16 12:30 /var/backups/vigilanza-turni/backup_20251016_123049.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 12:25 /var/backups/vigilanza-turni/backup_20251016_122541.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 12:01 /var/backups/vigilanza-turni/backup_20251016_120124.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:58 /var/backups/vigilanza-turni/backup_20251016_115804.sql.gz
-rw-r--r-- 1 root root 3.4K Oct 16 11:56 /var/backups/vigilanza-turni/backup_20251016_115644.sql.gz
 Applicazione disponibile su: https://vt.alfacom.it

159
server/localAuth.ts Normal file
View File

@ -0,0 +1,159 @@
// Sistema autenticazione locale per deployment server esterno (non-Replit)
import passport from "passport";
import { Strategy as LocalStrategy } from "passport-local";
import session from "express-session";
import type { Express } from "express";
import connectPg from "connect-pg-simple";
import { storage } from "./storage";
// Credenziali admin di default per demo/sviluppo
const DEFAULT_ADMIN_EMAIL = "admin@vt.alfacom.it";
const DEFAULT_ADMIN_PASSWORD = "admin123"; // CAMBIARE IN PRODUZIONE!
const DEFAULT_ADMIN_ID = "local-admin-vt";
export function getSession() {
const sessionTtl = 7 * 24 * 60 * 60 * 1000; // 1 settimana
const pgStore = connectPg(session);
const sessionStore = new pgStore({
conString: process.env.DATABASE_URL,
createTableIfMissing: false,
ttl: sessionTtl,
tableName: "sessions",
});
return session({
secret: process.env.SESSION_SECRET!,
store: sessionStore,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
maxAge: sessionTtl,
},
});
}
async function initDefaultAdmin() {
try {
// Verifica se esiste già un admin
const users = await storage.getAllUsers();
const adminExists = users.some((u: any) => u.email === DEFAULT_ADMIN_EMAIL);
if (!adminExists) {
// Crea utente admin di default
await storage.upsertUser({
id: DEFAULT_ADMIN_ID,
email: DEFAULT_ADMIN_EMAIL,
firstName: "Admin",
lastName: "Sistema",
profileImageUrl: null,
});
// Imposta ruolo admin
await storage.updateUserRole(DEFAULT_ADMIN_ID, "admin");
console.log(`✅ [LocalAuth] Admin di default creato: ${DEFAULT_ADMIN_EMAIL}`);
}
} catch (error) {
console.error("❌ [LocalAuth] Errore creazione admin:", error);
}
}
export async function setupLocalAuth(app: Express) {
app.set("trust proxy", 1);
app.use(getSession());
app.use(passport.initialize());
app.use(passport.session());
// Inizializza admin di default
await initDefaultAdmin();
// Strategia passport-local
passport.use(new LocalStrategy(
{ usernameField: "email" },
async (email, password, done) => {
try {
// Per demo: accetta credenziali admin di default
if (email === DEFAULT_ADMIN_EMAIL && password === DEFAULT_ADMIN_PASSWORD) {
const users = await storage.getAllUsers();
const admin = users.find((u: any) => u.email === DEFAULT_ADMIN_EMAIL);
if (admin) {
return done(null, { id: admin.id, email: admin.email });
}
}
// Credenziali non valide
return done(null, false, { message: "Credenziali non valide" });
} catch (error) {
return done(error);
}
}
));
passport.serializeUser((user: any, done) => {
done(null, user.id);
});
passport.deserializeUser(async (id: string, done) => {
try {
const users = await storage.getAllUsers();
const user = users.find((u: any) => u.id === id);
done(null, user || null);
} catch (error) {
done(error);
}
});
// Route login locale
app.post("/api/local-login", passport.authenticate("local"), (req, res) => {
res.json({
success: true,
user: req.user,
message: "Login effettuato con successo"
});
});
// Route auto-login admin (solo per demo/sviluppo)
app.get("/api/auto-login-admin", async (req, res) => {
if (process.env.NODE_ENV !== 'production') {
console.warn("⚠️ [LocalAuth] Auto-login admin attivato (solo sviluppo!)");
}
try {
const users = await storage.getAllUsers();
const admin = users.find((u: any) => u.email === DEFAULT_ADMIN_EMAIL);
if (admin) {
req.login({ id: admin.id, email: admin.email }, (err) => {
if (err) {
return res.status(500).json({ error: "Errore auto-login" });
}
res.redirect("/");
});
} else {
res.status(404).json({ error: "Admin non trovato" });
}
} catch (error) {
res.status(500).json({ error: "Errore server" });
}
});
// Route logout
app.get("/api/logout", (req, res) => {
req.logout(() => {
res.redirect("/");
});
});
console.log("✅ [LocalAuth] Sistema autenticazione locale attivato");
console.log(`📧 Email admin: ${DEFAULT_ADMIN_EMAIL}`);
console.log(`🔑 Password admin: ${DEFAULT_ADMIN_PASSWORD}`);
console.log(`🔗 Auto-login: GET /api/auto-login-admin`);
}
export const isAuthenticated = async (req: any, res: any, next: any) => {
if (!req.isAuthenticated()) {
return res.status(401).json({ message: "Unauthorized" });
}
next();
};

View File

@ -1,20 +1,42 @@
import type { Express } from "express";
import { createServer, type Server } from "http";
import { storage } from "./storage";
import { setupAuth, isAuthenticated } from "./replitAuth";
import { setupAuth as setupReplitAuth, isAuthenticated as isAuthenticatedReplit } from "./replitAuth";
import { setupLocalAuth, isAuthenticated as isAuthenticatedLocal } from "./localAuth";
import { db } from "./db";
import { guards, certifications, sites, shifts, shiftAssignments, users, insertShiftSchema } from "@shared/schema";
import { eq } from "drizzle-orm";
import { differenceInDays } from "date-fns";
// Determina quale sistema auth usare basandosi sull'ambiente
const USE_LOCAL_AUTH = process.env.DOMAIN === "vt.alfacom.it" || !process.env.REPLIT_DOMAINS;
// Helper per estrarre user ID in modo compatibile
function getUserId(req: any): string {
if (USE_LOCAL_AUTH) {
return req.user?.id || "";
} else {
return req.user?.claims?.sub || "";
}
}
// Usa il middleware auth appropriato
const isAuthenticated = USE_LOCAL_AUTH ? isAuthenticatedLocal : isAuthenticatedReplit;
export async function registerRoutes(app: Express): Promise<Server> {
// Auth middleware
await setupAuth(app);
// Setup auth system appropriato
if (USE_LOCAL_AUTH) {
console.log("🔐 Usando Local Auth (vt.alfacom.it)");
await setupLocalAuth(app);
} else {
console.log("🔐 Usando Replit OIDC Auth");
await setupReplitAuth(app);
}
// ============= AUTH ROUTES =============
app.get("/api/auth/user", isAuthenticated, async (req: any, res) => {
try {
const userId = req.user.claims.sub;
const userId = getUserId(req);
const user = await storage.getUser(userId);
res.json(user);
} catch (error) {
@ -26,7 +48,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
// ============= USER MANAGEMENT ROUTES =============
app.get("/api/users", isAuthenticated, async (req: any, res) => {
try {
const currentUserId = req.user.claims.sub;
const currentUserId = getUserId(req);
const currentUser = await storage.getUser(currentUserId);
// Only admins can view all users
@ -44,7 +66,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
app.patch("/api/users/:id", isAuthenticated, async (req: any, res) => {
try {
const currentUserId = req.user.claims.sub;
const currentUserId = getUserId(req);
const currentUser = await storage.getUser(currentUserId);
// Only admins can update user roles
@ -407,11 +429,11 @@ export async function registerRoutes(app: Express): Promise<Server> {
// ============= NOTIFICATION ROUTES =============
app.get("/api/notifications", isAuthenticated, async (req: any, res) => {
try {
const userId = req.user.claims.sub;
const userId = getUserId(req);
const userNotifications = await storage.getNotificationsByUser(userId);
res.json(userNotifications);
} catch (error) {
console.error("Error fetching notifications:", error);
console.error("Error fetching user notifications:", error);
res.status(500).json({ message: "Failed to fetch notifications" });
}
});