Vite proxy config simplified. Renaming /auth/restricted to have a trailing slash for better Vite compatibility.

This commit is contained in:
Leo Vasanko
2025-12-02 22:41:12 +00:00
parent c83450dace
commit aed48de38e
6 changed files with 16 additions and 50 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ function showAuthIframe() {
authIframe = document.createElement('iframe')
authIframe.id = 'auth-iframe'
authIframe.title = 'Authentication'
authIframe.src = '/auth/restricted?mode=login'
authIframe.src = '/auth/restricted/?mode=login'
document.body.appendChild(authIframe)
loadingMessage.value = 'Authentication required...'
}
+1 -1
View File
@@ -330,7 +330,7 @@ function showAuthIframe() {
authIframe = document.createElement('iframe')
authIframe.id = 'auth-iframe'
authIframe.title = 'Authentication'
authIframe.src = '/auth/restricted?mode=login'
authIframe.src = '/auth/restricted/?mode=login'
document.body.appendChild(authIframe)
loadingMessage.value = 'Authentication required...'
}
+9 -43
View File
@@ -2,7 +2,7 @@ import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import { resolve } from 'node:path'
import vue from '@vitejs/plugin-vue'
import { readFileSync, existsSync, statSync, renameSync, mkdirSync } from 'node:fs'
import { existsSync, renameSync, mkdirSync } from 'node:fs'
export default defineConfig(({ command }) => ({
appType: 'mpa',
@@ -45,53 +45,19 @@ export default defineConfig(({ command }) => ({
allow: ['..']
},
proxy: {
'/': {
target: 'http://localhost:4402',
bypass: (req) => {
const url = req.url?.split('?')[0]
// Root and examples served by Vite
if (url === '/' || url === '') return '/../examples/index.html'
if (url === '/examples' || url === '/examples/') return '/../examples/index.html'
if (url?.startsWith('/examples/')) return `/../examples${url.slice(9)}`
// Let other proxies handle their routes
return null
}
// Only proxy these two specific backend API paths
'/auth/api': {
target: 'http://localhost:4402'
},
'/auth/': {
'/auth/ws': {
target: 'http://localhost:4402',
ws: true,
bypass: (req) => {
const url = req.url?.split('?')[0]
// Backend handles /auth/api/* and /auth/ws/* (no bypass - let proxy handle)
if (url?.startsWith('/auth/api/') || url?.startsWith('/auth/ws/')) return null
// Vite serves all assets
if (url?.startsWith('/auth/assets/')) return url
// Vite serves main app routes
if (url === '/auth' || url === '/auth/') return '/auth/index.html'
if (url === '/auth/admin' || url === '/auth/admin/') return '/auth/admin/index.html'
if (url === '/auth/restricted' || url === '/auth/restricted/') return '/auth/restricted/index.html'
if (url?.startsWith('/auth/') && /^\/auth\/([a-z]+\.)+[a-z]+\/?/.test(url)) return "/int/reset/index.html"
// Vite serves source files (for HMR and dev)
if (url?.startsWith('/auth/') && /\.(js|vue|css|ts|jsx|tsx|json)$/.test(url)) return url
return null
}
},
'/int/': {
target: 'http://localhost:4402',
bypass: (req) => {
const url = req.url?.split('?')[0]
// Vite serves /int/ apps
if (url === '/int/host' || url === '/int/host/') return '/int/host/index.html'
if (url === '/int/reset' || url === '/int/reset/' || url?.match(/^\/int\/reset\/([a-z]+\.){4}[a-z]+\/?$/)) return '/int/reset/index.html'
if (url === '/int/forward' || url === '/int/forward/') return '/int/forward/index.html'
if (url?.startsWith('/int/')) return url
return null
}
ws: true
}
}
},
preview: {
port: 4403
},
build: {
outDir: '../passkey/frontend-build',
emptyOutDir: true,