49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
/// <reference types="vitest/config" />
|
|
import react from '@vitejs/plugin-react'
|
|
import { defineConfig, type ProxyOptions } from 'vite'
|
|
|
|
// The Go API behind this dev server. Override when the API runs elsewhere,
|
|
// e.g. API_URL=http://127.0.0.1:8080 npm run dev.
|
|
const apiUrl = process.env.API_URL ?? 'http://localhost:8080'
|
|
|
|
// /api is proxied so the browser only ever sees the vite origin
|
|
// (localhost or *.preview.k6n.net): OIDC redirects land on the same host
|
|
// and session cookies stay first-party. X-Forwarded-Host/Proto tell the
|
|
// backend which public origin to bake into redirect URIs — behind the
|
|
// preview ingress the incoming request already carries a forwarded proto,
|
|
// which wins over the local http connection.
|
|
const apiProxy: ProxyOptions = {
|
|
target: apiUrl,
|
|
configure: (proxy) => {
|
|
proxy.on('proxyReq', (proxyReq, req) => {
|
|
const host = req.headers.host
|
|
if (host !== undefined) proxyReq.setHeader('X-Forwarded-Host', host)
|
|
const protoHeader = req.headers['x-forwarded-proto']
|
|
const local = (req.socket as { encrypted?: boolean }).encrypted ? 'https' : 'http'
|
|
const proto = (Array.isArray(protoHeader) ? protoHeader[0] : protoHeader) ?? local
|
|
proxyReq.setHeader('X-Forwarded-Proto', proto)
|
|
})
|
|
},
|
|
}
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
allowedHosts: ['.preview.k6n.net'],
|
|
proxy: {
|
|
'/api': apiProxy,
|
|
},
|
|
},
|
|
test: {
|
|
globals: true,
|
|
environment: 'jsdom',
|
|
setupFiles: ['./tests/setup.ts'],
|
|
include: ['tests/**/*.test.{ts,tsx,mjs}', 'src/**/*.test.{ts,tsx}'],
|
|
// jsdom forks are memory-hungry; parallel workers can OOM on busy hosts.
|
|
maxWorkers: 2,
|
|
},
|
|
})
|