From c8c64d921f02eb72d0fbc4511d41d1f147bdbb0d Mon Sep 17 00:00:00 2001 From: Tobias Wilken Date: Thu, 4 Dec 2025 22:41:13 +0100 Subject: [PATCH] fix: use dynamic import for vite in development only Static import of vite fails in production because vite is a devDependency that gets pruned. Changed to dynamic import inside the isProduction check so the import only happens in development. --- server/index.js | 6 +++--- server/proxy.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index 2f8bccd..802f966 100644 --- a/server/index.js +++ b/server/index.js @@ -1,5 +1,4 @@ import express from 'express'; -import { createServer } from 'vite'; import fs from 'fs'; import proxy from './proxy.js'; @@ -12,6 +11,7 @@ async function startServer() { // Setup Vite middleware (development only) let vite; if (!isProduction) { + const { createServer } = await import('vite'); vite = await createServer({ server: { middlewareMode: true }, appType: 'custom', @@ -52,12 +52,12 @@ async function startServer() { // SPA routing - must be last! if (isProduction) { // Production: serve pre-built index.html - app.get('/*', (req, res) => { + app.get('/{*path}', (req, res) => { res.sendFile('index.html', { root: './dist' }); }); } else { // Development: use Vite to transform index.html - app.get('/*', async (req, res) => { + app.get('/{*path}', async (req, res) => { try { const template = await vite.transformIndexHtml( req.originalUrl, diff --git a/server/proxy.js b/server/proxy.js index 3056a90..a22e51c 100644 --- a/server/proxy.js +++ b/server/proxy.js @@ -11,7 +11,7 @@ console.log(`Proxy API requests to: ${apiURL}`); * Proxy all API requests to the worlddriven/core backend * Converts sessionId cookie to Authorization header */ -router.all('*', async (req, res) => { +router.all('/{*path}', async (req, res) => { try { // Extract sessionId from cookie and convert to Authorization header let authorization;