mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
81 lines
3.9 KiB
TypeScript
81 lines
3.9 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
// vitest/config's defineConfig is vite's own, augmented with the `test`
|
|
// field's types — importing from here (not 'vite') is what lets the
|
|
// `test` block below type-check under vue-tsc -b without a separate
|
|
// vitest.config.ts or a triple-slash type reference.
|
|
import { defineConfig } from 'vitest/config'
|
|
|
|
import { mockAdminApi } from './mock/server.ts'
|
|
import { themeBoot } from './vite-plugins/theme-boot.ts'
|
|
|
|
// MOCK=1 serves /admin/api/* from webui/mock (dev server only; apply: 'serve' keeps it out of vite build).
|
|
const useMock = process.env.MOCK === '1'
|
|
|
|
// Keep identical to adminCSP in ../admin.go: `vite preview` serves the built dist under it so a CSP violation shows up in the browser console.
|
|
const ADMIN_CSP =
|
|
"default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'none'; form-action 'none'"
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
// admin.go serves this build's index.html at GET /admin and every hashed
|
|
// asset at GET /admin/assets/{hashedname} — the base must match so the
|
|
// emitted index.html's own <script>/<link> references resolve correctly
|
|
// regardless of what path the browser first loaded the page from.
|
|
base: '/admin/',
|
|
plugins: [vue(), tailwindcss(), themeBoot(), ...(useMock ? [mockAdminApi()] : [])],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
build: {
|
|
// No inline bootstrap script in the emitted index.html (admin.go's CSP
|
|
// ships script-src 'self' with no 'unsafe-inline' — see the Go-side
|
|
// asset-serving comment for the full rationale): Vite's module-preload
|
|
// polyfill is otherwise inlined as a <script> tag, which that CSP would
|
|
// block. Disabling it leaves only <link rel="modulepreload"> hints,
|
|
// which need no script-src allowance at all. The admin panel only ever
|
|
// targets current evergreen browsers (native ES module support), so the
|
|
// polyfill has nothing to do here anyway.
|
|
modulePreload: { polyfill: false },
|
|
},
|
|
preview: { headers: { 'Content-Security-Policy': ADMIN_CSP } },
|
|
server: {
|
|
// `npm run dev` serves this app at :5173 (or whatever Vite picks), but
|
|
// every fetch('/admin/api/...') (lib/api.ts) is a same-origin, relative
|
|
// path — without a proxy it hits Vite itself, which has no such route
|
|
// and answers with a 404 or the index.html SPA fallback, so the dev
|
|
// build can never actually load data. Proxying just the API path (not
|
|
// '/admin' itself) leaves Vite serving this project's own index.html/
|
|
// HMR client at '/admin/' as usual. The target is env-configurable
|
|
// (ADMIN_API_PROXY_TARGET) rather than hardcoded, since which gateway
|
|
// instance a developer is pointed at varies by machine; the fallback
|
|
// matches this repo's own `run-local`/integration default port.
|
|
proxy: useMock
|
|
? undefined
|
|
: {
|
|
'/admin/api': {
|
|
target: process.env.ADMIN_API_PROXY_TARGET ?? 'http://localhost:8080',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
test: {
|
|
// Deliberately narrow: lib/'s pure modules (search-expand.ts,
|
|
// usage-search.ts) plus, since review round 2 (v0.21), stores/
|
|
// dashboard.ts's own refresh() action — a Pinia store is plain
|
|
// reactive state and actions, no DOM or component mount involved, so
|
|
// it fits this same environment. Still no snapshot/DOM/component
|
|
// (.vue mount) testing. 'node' is enough since nothing under test
|
|
// touches a real browser global — dashboard.spec.ts mocks lib/api.ts
|
|
// entirely, so even sessionStorage access (auth.ts) never actually
|
|
// runs; jsdom is not pulled in as a dependency for modules that don't
|
|
// need it.
|
|
environment: 'node',
|
|
include: ['src/**/*.spec.ts'],
|
|
},
|
|
})
|