-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
65 lines (61 loc) · 1.8 KB
/
vite.config.ts
File metadata and controls
65 lines (61 loc) · 1.8 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 fs from 'fs'
import path from 'path'
const isLocalDev = !!process.env.DEV_PROXY_VPS;
const VPS_ORIGIN = process.env.DEV_PROXY_VPS || 'https://localhost:5174';
// noVNC ESM files live in public/browser/lib/ and are copied to dist/ automatically by Vite.
// The @novnc/novnc npm package ships CJS only; we vendor the ESM source from the noVNC repo instead.
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: '0.0.0.0',
port: isLocalDev ? 5174 : 3001,
allowedHosts: true,
...(!isLocalDev && fs.existsSync(path.resolve(__dirname, 'localhost+2-key.pem')) ? {
https: {
key: fs.readFileSync(path.resolve(__dirname, 'localhost+2-key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, 'localhost+2.pem'))
}
} : {}),
proxy: isLocalDev ? {
// Dev on control server: proxy to VPS
'/gateway': {
target: VPS_ORIGIN.replace('https', 'wss'),
ws: true,
changeOrigin: true,
secure: true
},
'/api': {
target: VPS_ORIGIN,
changeOrigin: true,
secure: true
}
} : {
// Dev on VPS itself: proxy to local services
'/gateway': {
target: 'ws://127.0.0.1:18789',
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/gateway/, ''),
secure: false,
headers: {
'X-Forwarded-For': '127.0.0.1',
'X-Forwarded-Proto': 'http',
}
},
'/api': {
target: 'http://localhost:3002',
changeOrigin: true,
secure: false
},
'/browser': {
target: 'http://localhost:3002',
changeOrigin: true,
ws: true,
secure: false
}
}
}
})