-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.admin.config.js
More file actions
64 lines (59 loc) · 2.11 KB
/
vite.admin.config.js
File metadata and controls
64 lines (59 loc) · 2.11 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import basicSsl from '@vitejs/plugin-basic-ssl'
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
basicSsl(),
{
name: 'index-html-rewrite',
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
// Force serve admin.html for root and SPA routes
if (req.url === '/' || (!req.url.includes('.') && req.headers.accept?.includes('text/html'))) {
try {
const fs = await import('fs');
const path = await import('path');
// Read admin.html
const template = fs.readFileSync(resolve(__dirname, 'admin.html'), 'utf-8');
// Transform HTML (inject Vite scripts)
const html = await server.transformIndexHtml(req.url, template);
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(html);
return;
} catch (e) {
console.error('Error serving admin.html:', e);
next(e);
}
}
next();
});
}
}
],
cacheDir: './node_modules/.vite_admin',
server: {
port: 5174,
open: '/admin.html',
proxy: {
'/api': {
target: 'http://localhost:4000',
changeOrigin: true,
secure: false, // Allow self-signed certs
},
},
},
build: {
rollupOptions: {
input: {
admin: resolve(__dirname, 'admin.html')
}
}
}
})