Vite devserver configuration that behaves correctly for auth-host, serving the profile view at site root and /admin/ instead of under /auth/.

This commit is contained in:
2025-12-10 18:18:14 +00:00
parent 2d797454de
commit 4a753ca29b
2 changed files with 40 additions and 4 deletions
+34 -1
View File
@@ -5,17 +5,50 @@ import vue from '@vitejs/plugin-vue'
import { existsSync, renameSync, mkdirSync } from 'node:fs'
import sirv from 'sirv'
// Auth host mode: when set, clients accessing the auth host get /auth/ at / and /auth/admin/ at /admin/
const authHost = process.env.PASKIA_AUTH_HOST
export default defineConfig(({ command }) => ({
appType: 'mpa',
publicDir: 'public',
plugins: [
vue(),
// Auth host routing: rewrite paths when accessing dedicated auth host
// Must run before serve-examples to handle / correctly
authHost && {
name: 'auth-host-routing',
configureServer(server) {
server.middlewares.use((req, _res, next) => {
const host = req.headers.host?.split(':')[0]
// Check if request is coming to the auth host
if (host === authHost) {
// Only rewrite specific paths that should map to /auth/*
// Rewrite / and /index.html to /auth/
if (req.url === '/' || req.url === '/index.html') {
req.url = '/auth/'
}
// Rewrite /admin/* to /auth/admin/*
else if (req.url.startsWith('/admin/') || req.url === '/admin') {
req.url = '/auth' + req.url
}
// Everything else (Vite paths, passphrase links, etc.) passes through unchanged
}
next()
})
}
},
{
name: 'serve-examples',
configureServer(server) {
const examplesDir = resolve(__dirname, '../examples')
const serve = sirv(examplesDir, { dev: true })
server.middlewares.use((req, _res, next) => {
// Skip redirect to examples on auth host (handled by auth-host-routing)
const host = req.headers.host?.split(':')[0]
if (authHost && host === authHost) {
next()
return
}
if (req.url === '/' || req.url === '/index.html') req.url = '/examples/'
next()
})
@@ -46,7 +79,7 @@ export default defineConfig(({ command }) => ({
}
}
}
],
].filter(Boolean),
resolve: {
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }
},