diff --git a/.env.v2 b/.env.v2 new file mode 100644 index 0000000..b656a3a --- /dev/null +++ b/.env.v2 @@ -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 /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 diff --git a/.gitignore b/.gitignore index cf9eabc..232669c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules dist dist-staging +dist-v2 .env *.log tsconfig.tsbuildinfo diff --git a/deploy/nginx-mams-v2.conf b/deploy/nginx-mams-v2.conf new file mode 100644 index 0000000..9686baa --- /dev/null +++ b/deploy/nginx-mams-v2.conf @@ -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 +# } diff --git a/package.json b/package.json index 32d4d01..553046a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dev:staging": "vite --mode staging", "build": "tsc -b && vite build", "build:staging": "tsc -b && vite build --mode staging", + "build:v2": "tsc -b && vite build --mode v2", "preview": "vite preview", "preview:staging": "vite preview --mode staging", "start": "vite build && vite preview", diff --git a/vite.config.ts b/vite.config.ts index c898978..eca74a0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -15,7 +15,7 @@ export default defineConfig(({ mode }) => { preview: { port: 4173, proxy }, 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, target: 'es2022', rollupOptions: {