Skip to content

Commit 7c618b1

Browse files
authored
fix: use dynamic import for vite in development only (#4)
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.
1 parent 90c6c2e commit 7c618b1

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

server/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import express from 'express';
2-
import { createServer } from 'vite';
32
import fs from 'fs';
43
import proxy from './proxy.js';
54

@@ -12,6 +11,7 @@ async function startServer() {
1211
// Setup Vite middleware (development only)
1312
let vite;
1413
if (!isProduction) {
14+
const { createServer } = await import('vite');
1515
vite = await createServer({
1616
server: { middlewareMode: true },
1717
appType: 'custom',
@@ -52,12 +52,12 @@ async function startServer() {
5252
// SPA routing - must be last!
5353
if (isProduction) {
5454
// Production: serve pre-built index.html
55-
app.get('/*', (req, res) => {
55+
app.get('/{*path}', (req, res) => {
5656
res.sendFile('index.html', { root: './dist' });
5757
});
5858
} else {
5959
// Development: use Vite to transform index.html
60-
app.get('/*', async (req, res) => {
60+
app.get('/{*path}', async (req, res) => {
6161
try {
6262
const template = await vite.transformIndexHtml(
6363
req.originalUrl,

server/proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ console.log(`Proxy API requests to: ${apiURL}`);
1111
* Proxy all API requests to the worlddriven/core backend
1212
* Converts sessionId cookie to Authorization header
1313
*/
14-
router.all('*', async (req, res) => {
14+
router.all('/{*path}', async (req, res) => {
1515
try {
1616
// Extract sessionId from cookie and convert to Authorization header
1717
let authorization;

0 commit comments

Comments
 (0)