From 41e90efd8bc3fd842f4c3527020238e8517eafba Mon Sep 17 00:00:00 2001 From: Tobias Wilken Date: Sun, 18 Jan 2026 08:05:38 +0100 Subject: [PATCH] fix: properly separate static pages from Vite-built React pages - Move React HTML entry points (dashboard, admin, pull_request) to root - Remove old root index.html (Vite shell) - landing page is in public/ - Configure Vite with multi-page rollupOptions.input for React pages only - Set publicDir: false so Vite doesn't interfere with public/ folder - Update server to serve static files from public/, React from dist/ - Fix HTML files to use consistent script/css references Architecture: - public/ contains static pages (landing, imprint, privacy) served directly - Root HTML files are Vite entry points, built to dist/ - In production: static from public/, React pages from dist/ - In development: Vite middleware transforms React pages on the fly --- index.html => admin.html | 0 public/dashboard.html => dashboard.html | 0 public/admin.html | 22 ------------------- public/pull_request.html => pull_request.html | 4 ++-- server/index.js | 22 +++++++++++++------ vite.config.js | 18 +++++++++++++++ 6 files changed, 35 insertions(+), 31 deletions(-) rename index.html => admin.html (100%) rename public/dashboard.html => dashboard.html (100%) delete mode 100644 public/admin.html rename public/pull_request.html => pull_request.html (82%) diff --git a/index.html b/admin.html similarity index 100% rename from index.html rename to admin.html diff --git a/public/dashboard.html b/dashboard.html similarity index 100% rename from public/dashboard.html rename to dashboard.html diff --git a/public/admin.html b/public/admin.html deleted file mode 100644 index 77a855c..0000000 --- a/public/admin.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - World driven - - - - - - - -
- - - diff --git a/public/pull_request.html b/pull_request.html similarity index 82% rename from public/pull_request.html rename to pull_request.html index d09f6d4..5bc9d12 100644 --- a/public/pull_request.html +++ b/pull_request.html @@ -12,7 +12,7 @@ name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> - + @@ -20,6 +20,6 @@
- + diff --git a/server/index.js b/server/index.js index a9170d3..ba5f65e 100644 --- a/server/index.js +++ b/server/index.js @@ -27,7 +27,7 @@ async function startServer() { }); }); - // Proxy API requests to backend - MUST be before Vite middleware + // Proxy API requests to backend - MUST be before static/Vite middleware app.use('/api', proxy); // Setup Vite middleware (development only) @@ -41,10 +41,15 @@ async function startServer() { app.use(vite.middlewares); } - // Serve static files + // Serve static files (landing page, images, css) app.use(express.static('./public')); - // Static pages (no React) + // In production, serve built assets from dist/ + if (isProduction) { + app.use(express.static('./dist')); + } + + // Static pages (no React) - served from public/ app.get('/', (req, res) => { res.sendFile('index.html', { root: './public' }); }); @@ -57,15 +62,17 @@ async function startServer() { res.sendFile('privacyPolicy.html', { root: './public' }); }); - // React pages - use Vite in development + // React pages - serve from dist/ in production, transform with Vite in development const serveReactPage = async (req, res, htmlFile) => { if (isProduction) { - res.sendFile(htmlFile, { root: './public' }); + // Serve pre-built HTML from dist/ + res.sendFile(htmlFile, { root: './dist' }); } else { + // Transform HTML with Vite (handles JSX imports) try { const template = await vite.transformIndexHtml( req.originalUrl, - fs.readFileSync(path.join('./public', htmlFile), 'utf-8') + fs.readFileSync(path.join('.', htmlFile), 'utf-8') ); res.setHeader('Content-Type', 'text/html'); res.send(template); @@ -80,7 +87,8 @@ async function startServer() { app.get('/dashboard', (req, res) => serveReactPage(req, res, 'dashboard.html') ); - app.get('/admin', (req, res) => serveReactPage(req, res, 'dashboard.html')); + + app.get('/admin', (req, res) => serveReactPage(req, res, 'admin.html')); // PR pages: /:owner/:repo/pull/:number app.get('/:owner/:repo/pull/:number', (req, res) => { diff --git a/vite.config.js b/vite.config.js index a8badb8..9b91d15 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,12 +1,30 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +import { resolve } from 'path'; export default defineConfig({ plugins: [react()], + + // Don't copy public/ to dist/ - we serve static files separately + publicDir: false, + + build: { + outDir: 'dist', + emptyOutDir: true, + rollupOptions: { + input: { + dashboard: resolve(__dirname, 'dashboard.html'), + pullRequest: resolve(__dirname, 'pull_request.html'), + admin: resolve(__dirname, 'admin.html'), + }, + }, + }, + server: { host: '0.0.0.0', port: 3001, }, + css: { modules: { localsConvention: 'camelCaseOnly',