-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.js
More file actions
34 lines (31 loc) · 986 Bytes
/
Copy pathvite.config.js
File metadata and controls
34 lines (31 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [
react(),
{
name: 'spa-fallback',
configureServer(server) {
server.middlewares.use((req, _res, next) => {
const url = req.url?.split('?')[0] ?? '';
const isViteInternal = url.startsWith('/@') || url.startsWith('/node_modules');
const isAsset = url.includes('.');
const isApi = url.startsWith('/api');
// Static HTML routes — check these before SPA fallback
if (url === '/story' || url === '/story/') {
req.url = '/story.html';
} else if (url === '/comparison' || url === '/comparison/') {
req.url = '/comparison.html';
} else if (!isViteInternal && !isAsset && !isApi && url !== '/') {
req.url = '/';
}
next();
});
}
}
],
server: {
port: 3000,
strictPort: true,
}
})