-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
103 lines (99 loc) · 2.65 KB
/
vite.config.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { URL, fileURLToPath } from 'node:url'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver, HeadlessUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import type { HttpProxy, ProxyOptions } from 'vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
vue(),
Components({
dts: true,
resolvers: [
HeadlessUiResolver(),
ElementPlusResolver(),
],
dirs: [
'src',
],
}),
AutoImport({
resolvers: [
ElementPlusResolver(),
],
imports: [
'vue',
'vue-router',
'@vueuse/core',
'pinia',
],
dirs: [
'src/composables',
'src/stores',
'src/utils',
],
}),
UnoCSS(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
host: '127.0.0.1',
port: 3000,
proxy: {
'/passport': {
target: 'https://passport.bilibili.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/passport/, ''),
configure,
},
'/api': {
target: 'https://api.bilibili.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
configure,
},
'/biilii': {
target: 'https://www.bilibili.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/biilii/, ''),
configure: (proxy, options) => configure(proxy, options, 'path=/api/x/web-interface/search;'),
},
'/bilivideo': {
target: 'https://cn-sxxa-cm-01-04.bilivideo.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/bilivideo\/.*?\//, ''),
configure,
},
},
},
})
function configure(proxy: HttpProxy.Server, options: ProxyOptions, pathReplace?: string) {
options.headers = {
referer: 'https://www.bilibili.com',
oringin: '',
}
proxy.on('proxyReq', (proxyReq) => {
if (proxyReq.path.includes('/bilivideo')) {
const target = proxyReq.path.match(/\/bilivideo\/(.*?)\//)![1]
if (target)
options.target = `https://${target}/`
}
})
proxy.on('proxyRes', (proxyRes) => {
proxyRes.headers['set-cookie']
= proxyRes.headers['set-cookie']
?.map((cookie) => {
cookie = cookie.replace(/[D|d]omain=.*?bilibili.com(;)*/, '')
.replace('HttpOnly; Secure', '')
if (pathReplace)
cookie = cookie.replace('path=/;', pathReplace)
return cookie
})
})
}