- The raw-source contract tests read files from disk (rawSources.testkit) instead of import.meta.glob, which knip counted as importing every src file — its unused-files lane could never name an orphan. knip now names src/watchMain.tsx as an entry (registered in docs/gates.md). - vite build fails when index.html or watch.html is not emitted. - The watch-entry import walk follows dynamic import() too. - audit_metrics.py's plan-code patterns are held equal to the guard's. - CrashBoundary is domain-free: it moves into components/ui.
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
import { defineConfig, type Plugin } from "vite";
|
|
import { reactWithCompiler } from "./reactPlugin";
|
|
import { devOnlyGuard } from "./devOnlyGuard";
|
|
|
|
// During `vite dev` (host with Node), proxy API calls to the backend container.
|
|
// Use 127.0.0.1 (not "localhost") so Node doesn't resolve to IPv6 ::1, which the
|
|
// Docker port publish may not answer — that surfaces as proxy connection failures.
|
|
const target = "http://127.0.0.1:8080";
|
|
// changeOrigin:false keeps the original `Host: localhost:5173` header when proxying to the backend
|
|
// (the TCP target is still 127.0.0.1:8080 — changeOrigin only rewrites the header). The backend uses
|
|
// that header to send the OAuth redirect_uri back to :5173, so a Google login started on the Vite dev
|
|
// server returns to :5173 instead of the fixed :8080 callback. (Both are registered in the console.)
|
|
const proxyOpts = { target, changeOrigin: false };
|
|
const proxy = {
|
|
"/api": proxyOpts,
|
|
"/auth": proxyOpts,
|
|
"/healthz": proxyOpts,
|
|
};
|
|
|
|
// Two HTML entries: the app (index.html) and a public /watch/<token> link (watch.html), which loads
|
|
// only the player page. In a build the backend picks the file by path (`main.py`); this does the
|
|
// same for `vite dev`, whose history fallback would otherwise hand /watch/… the app.
|
|
const watchEntry = (): Plugin => ({
|
|
name: "siftlode-watch-entry",
|
|
configureServer(server) {
|
|
server.middlewares.use((req, _res, next) => {
|
|
if (req.url?.startsWith("/watch/")) req.url = "/watch.html";
|
|
next();
|
|
});
|
|
},
|
|
// The server answers every /watch/ link with the built watch.html, so a build without it would
|
|
// ship a 500 for each one, and nothing downstream reads `dist` before prod does. Fail it here —
|
|
// after Vite's own HTML plugin has emitted the pages (`enforce: "post"`), or none is there yet.
|
|
enforce: "post",
|
|
generateBundle(_options, bundle) {
|
|
for (const page of ["index.html", "watch.html"]) {
|
|
if (!(page in bundle)) this.error(`${page} was not built — add it to rollupOptions.input`);
|
|
}
|
|
},
|
|
});
|
|
|
|
export default defineConfig({
|
|
plugins: [reactWithCompiler(), devOnlyGuard(), watchEntry()],
|
|
server: { port: 5173, proxy },
|
|
build: { outDir: "dist", rollupOptions: { input: ["index.html", "watch.html"] } },
|
|
});
|