From 1edea25862ec299409207f43b6851cecb086d2d9 Mon Sep 17 00:00:00 2001 From: Padreug Date: Mon, 27 Apr 2026 17:43:49 +0200 Subject: [PATCH] feat: support path-based deployment for standalone apps Add VITE_BASE_PATH support to standalone app configs so they can be served under a path prefix (e.g., app.domain.com/sortir/) instead of a separate subdomain. This enables shared auth via same-origin localStorage. - Vite configs: configurable base path via VITE_BASE_PATH env var - Routers: use import.meta.env.BASE_URL for history base - PWA manifests: use base path for start_url and scope - Default: / (backward compatible with subdomain mode) Co-Authored-By: Claude Opus 4.6 (1M context) --- src/accounting-app/app.ts | 2 +- src/activities-app/app.ts | 2 +- vite.activities.config.ts | 10 +++++++--- vite.castle.config.ts | 7 ++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/accounting-app/app.ts b/src/accounting-app/app.ts index ea03522..6bcf423 100644 --- a/src/accounting-app/app.ts +++ b/src/accounting-app/app.ts @@ -54,7 +54,7 @@ export async function createAppInstance() { ].filter(Boolean) const router = createRouter({ - history: createWebHistory(), + history: createWebHistory(import.meta.env.BASE_URL), routes: [ // Record page is the home page in standalone mode { diff --git a/src/activities-app/app.ts b/src/activities-app/app.ts index 14f29c1..77da27d 100644 --- a/src/activities-app/app.ts +++ b/src/activities-app/app.ts @@ -50,7 +50,7 @@ export async function createAppInstance() { ].filter(Boolean) const router = createRouter({ - history: createWebHistory(), + history: createWebHistory(import.meta.env.BASE_URL), routes: [ // Activities page is the home page in standalone mode { diff --git a/vite.activities.config.ts b/vite.activities.config.ts index 59329b3..c7a4de8 100644 --- a/vite.activities.config.ts +++ b/vite.activities.config.ts @@ -33,9 +33,13 @@ function activitiesHtmlPlugin(): Plugin { /** * Vite config for the standalone Sortir activities app. - * Deployed to sortir.ariege.io + * + * Set VITE_BASE_PATH to deploy under a path prefix: + * VITE_BASE_PATH=/sortir/ → app.ariege.io/sortir/ (shared auth) + * (default: /) → sortir.ariege.io (standalone subdomain) */ export default defineConfig(({ mode }) => ({ + base: process.env.VITE_BASE_PATH || '/', plugins: [ activitiesHtmlPlugin(), vue(), @@ -65,8 +69,8 @@ export default defineConfig(({ mode }) => ({ background_color: '#ffffff', display: 'standalone', orientation: 'portrait-primary', - start_url: '/', - scope: '/', + start_url: process.env.VITE_BASE_PATH || '/', + scope: process.env.VITE_BASE_PATH || '/', id: 'sortir-activities', categories: ['social', 'entertainment', 'lifestyle'], lang: 'fr', diff --git a/vite.castle.config.ts b/vite.castle.config.ts index d652c46..4d928c2 100644 --- a/vite.castle.config.ts +++ b/vite.castle.config.ts @@ -33,8 +33,13 @@ function castleHtmlPlugin(): Plugin { /** * Vite config for the standalone Castle accounting app. + * + * Set VITE_BASE_PATH to deploy under a path prefix: + * VITE_BASE_PATH=/castle/ → app.ariege.io/castle/ (shared auth) + * (default: /) → castle.ariege.io (standalone subdomain) */ export default defineConfig(({ mode }) => ({ + base: process.env.VITE_BASE_PATH || '/', plugins: [ castleHtmlPlugin(), vue(), @@ -64,7 +69,7 @@ export default defineConfig(({ mode }) => ({ background_color: '#ffffff', display: 'standalone', orientation: 'portrait-primary', - start_url: '/', + start_url: process.env.VITE_BASE_PATH || '/', scope: '/', id: 'castle-accounting', categories: ['finance', 'business', 'productivity'],