Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
62 lines (61 loc) · 1.75 KB
/
Copy pathvite.config.ts
File metadata and controls
62 lines (61 loc) · 1.75 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
/// <reference types="vitest/config" />
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
test: {
environment: 'node',
include: ['src/**/*.test.{ts,tsx}', 'api/**/*.test.{ts,tsx}'],
},
server: {
proxy: {
'/api': {
target: 'https://node.gitlawb.com',
changeOrigin: true,
secure: true,
bypass(req) {
const url = req.url!
const localPath = path.resolve(__dirname, url.slice(1))
if (fs.existsSync(localPath)) {
return url
}
},
},
// Node identity lives at the node's root path, which the SPA occupies locally.
'/node-info': {
target: 'https://node.gitlawb.com',
changeOrigin: true,
secure: true,
rewrite: () => '/',
},
// Peer nodes for the network page (no CORS on nodes — same list as
// vercel.json and src/lib/nodes.ts). `/nodes/<id>/node-info` maps to the
// peer's root; everything else keeps its path with the prefix stripped.
...Object.fromEntries(
[
['node2', 'https://node2.gitlawb.com'],
['node3', 'https://node3.gitlawb.com'],
['manila', 'https://manila.gitlawb.com'],
].map(([id, target]) => [
`/nodes/${id}`,
{
target,
changeOrigin: true,
secure: true,
rewrite: (path: string) => {
const rest = path.slice(`/nodes/${id}`.length)
return rest === '/node-info' ? '/' : rest
},
},
]),
),
},
},
})