Add a /v2/ build mode and nginx config for serving under mams.nafith.om

- .env.v2 and `npm run build:v2` (base /v2/, output dist-v2/)
- deploy/nginx-mams-v2.conf: serve the app at https://mams.nafith.om/v2/ so the existing reCAPTCHA key works

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Samer Salameh 2026-11-12 11:17:44 +03:00
parent f9754cd75f
commit a01c9324c3
5 changed files with 47 additions and 1 deletions

7
.env.v2 Normal file
View File

@ -0,0 +1,7 @@
# The temporary copy served under https://mams.nafith.om/v2/ so the existing reCAPTCHA key (registered for mams.nafith.om) works.
# Build: npm run build:v2 -> dist-v2/ (copy its contents to <web root>/v2/ on the mams.nafith.om server)
VITE_BASE=/v2/
# The backend is on the same host as the page (/backend/core/controller.cfc, /index.cfm at the site root), so no prefix.
# If the backend is on another host and reached through a proxy path (e.g. /v2/api/), set VITE_API_BASE=/v2/api here instead.
VITE_API_BASE=
VITE_BACKEND_PUBLIC_ORIGIN=https://mams.nafith.om

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules node_modules
dist dist
dist-staging dist-staging
dist-v2
.env .env
*.log *.log
tsconfig.tsbuildinfo tsconfig.tsbuildinfo

37
deploy/nginx-mams-v2.conf Normal file
View File

@ -0,0 +1,37 @@
# nginx: serve the new front end at https://mams.nafith.om/v2/ (so the reCAPTCHA key registered for mams.nafith.om works).
#
# 1. build: npm run build:v2 (reads .env.v2, writes dist-v2/)
# 2. copy: the CONTENTS of dist-v2/ to /var/www/mams-v2/v2/ (note the extra "v2" folder)
# 3. add the block below INSIDE the existing `server { ... }` of mams.nafith.om, before any catch-all `location /`
# 4. test and reload: sudo nginx -t && sudo systemctl reload nginx
#
# The new app calls the backend at the site root (/backend/core/controller.cfc, /index.cfm), exactly like the old one, so no
# proxy rule is needed while the backend is on this same host. If the backend is on another host, see the second block.
# --- the single-page app under /v2/ ---
location ^~ /v2/ {
root /var/www/mams-v2; # files live in /var/www/mams-v2/v2/
index index.html;
try_files $uri $uri/ /v2/index.html; # any app route (/v2/e/TRUCKS/grid, /v2/caching …) serves index.html
}
# hashed assets never change: cache them for a year; index.html must never be cached
location ^~ /v2/assets/ {
root /var/www/mams-v2;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
location = /v2/index.html {
root /var/www/mams-v2;
add_header Cache-Control "no-cache";
}
# --- only if the backend is on ANOTHER host: forward /v2/api/ to it and build with VITE_API_BASE=/v2/api ---
# location ^~ /v2/api/ {
# proxy_pass https://mamsbe.nafith.om/;
# proxy_ssl_server_name on;
# proxy_set_header Host mamsbe.nafith.om;
# proxy_cookie_domain mamsbe.nafith.om mams.nafith.om;
# proxy_read_timeout 180s; # login and large exports can take 15 s or more
# client_max_body_size 50m; # attachment uploads, the backend's own limit
# }

View File

@ -8,6 +8,7 @@
"dev:staging": "vite --mode staging", "dev:staging": "vite --mode staging",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"build:staging": "tsc -b && vite build --mode staging", "build:staging": "tsc -b && vite build --mode staging",
"build:v2": "tsc -b && vite build --mode v2",
"preview": "vite preview", "preview": "vite preview",
"preview:staging": "vite preview --mode staging", "preview:staging": "vite preview --mode staging",
"start": "vite build && vite preview", "start": "vite build && vite preview",

View File

@ -15,7 +15,7 @@ export default defineConfig(({ mode }) => {
preview: { port: 4173, proxy }, preview: { port: 4173, proxy },
build: { build: {
// staging builds go to their own folder so they never overwrite (or get deployed as) the production build // staging builds go to their own folder so they never overwrite (or get deployed as) the production build
outDir: mode === 'staging' ? 'dist-staging' : 'dist', outDir: mode === 'staging' ? 'dist-staging' : mode === 'v2' ? 'dist-v2' : 'dist',
sourcemap: false, sourcemap: false,
target: 'es2022', target: 'es2022',
rollupOptions: { rollupOptions: {