Files
slp-modular-cms/frontend/vite.config.ts
T
SluijsensandClaude Sonnet 5.5 88f5d20a78 Voeg Api.AndreaSlopFotografie toe met setup-token, proxy-bewuste limiters en ASF-admin-thema
- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres
  (zonder configuratie ongewijzigd gedrag)
- Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de
  login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007)
- Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability)
  met bijbehorende tests
- Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina
- CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED
- Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 01:16:34 +01:00

102 lines
4.0 KiB
TypeScript

/// <reference types="vitest/config" />
import path from 'node:path';
import fs from 'node:fs';
import { defineConfig, loadEnv, type Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { version } from './package.json';
import { resolveTheme } from './themes/resolveTheme';
/** VITE_THEME selects themes/<name>/theme.css at build time (unset = today's admin, unchanged). */
function themeFor(mode: string) {
return resolveTheme({ ...loadEnv(mode, process.cwd(), 'VITE_'), ...process.env }.VITE_THEME);
}
/**
* Per-site favicon (VITE_THEME): the page links the theme favicon instead of the default one.
* Build emits it as an asset; the dev server serves it from the theme folder.
*/
function themeFavicon(faviconPath: string | null): Plugin {
const publicName = 'favicon-theme.svg';
return {
name: 'cms-theme-favicon',
// 'post': Vite has already prefixed the base path (/admin/) by then, so match any prefix.
transformIndexHtml: {
order: 'post',
handler(html) {
return faviconPath === null ? html : html.replace(/href="([^"]*)favicon\.svg"/, `href="$1${publicName}"`);
},
},
configureServer(server) {
if (faviconPath === null) return;
server.middlewares.use(`/${publicName}`, (_req, res) => {
res.setHeader('Content-Type', 'image/svg+xml');
res.end(fs.readFileSync(faviconPath));
});
},
generateBundle() {
if (faviconPath === null) return;
this.emitFile({ type: 'asset', fileName: publicName, source: fs.readFileSync(faviconPath) });
},
};
}
// https://vite.dev/config/
export default defineConfig(({ command, mode }) => ({
// Production builds are deployed under /admin (see Program.cs); the dev server keeps serving from '/'.
base: command === 'build' ? '/admin/' : '/',
plugins: [react(), tailwindcss(), themeFavicon(themeFor(mode).favicon)],
define: {
// Injected at build time, used as the Sentry `release` tag (see src/lib/sentry.ts).
__APP_VERSION__: JSON.stringify(version),
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
// The selected theme's CSS (or an empty file); imported once from main.tsx.
'@theme': themeFor(mode).css,
},
},
server: {
port: 5173,
proxy: {
// Mirrors the tunnel path the API serves in test and production, so the same
// Sentry `tunnel` option also works during `pnpm dev` — where this SPA runs on
// 5173 and the API on 7221.
//
// Note this targets our own API rather than Sentry's ingest host directly. The
// reference project proxies straight to Sentry, which forces the DSN's project id
// into this file and requires keeping it in sync by hand. The API derives the
// destination from its own DSN, so there is nothing to synchronise and no project
// id in a committed file.
'/sentry-tunnel': {
target: 'https://localhost:7221',
changeOrigin: true,
secure: false,
},
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
testTimeout: 20000,
css: true,
coverage: {
provider: 'v8',
reporter: ['text', 'html'],
include: ['src/**/*.{ts,tsx}'],
exclude: [
'src/**/*.test.{ts,tsx}',
'src/test/**',
'src/mocks/**',
'src/main.tsx',
'src/vite-env.d.ts',
// Calls Sentry.init, which cannot run meaningfully under jsdom; its skip-without-
// a-DSN behaviour is covered by a test that asserts init was not called.
'src/lib/sentry.ts',
],
},
},
}));