-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
40 lines (38 loc) · 1.11 KB
/
Copy pathvite.config.js
File metadata and controls
40 lines (38 loc) · 1.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
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
// Load environment variables unconditionally from .env files
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [react()],
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
},
},
},
server: {
proxy: {
'/api': {
target: 'https://cricket.sportmonks.com/api/v2.0',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
configure: (proxy) => {
// Inject API token cleanly without exposing to frontend
proxy.on('proxyReq', (proxyReq) => {
const token = env.SPORTMONKS_API_TOKEN
if (token) {
const reqPath = proxyReq.path
const separator = reqPath.includes('?') ? '&' : '?'
proxyReq.path = `${reqPath}${separator}api_token=${token}`
}
})
},
},
},
},
}
})