-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
66 lines (64 loc) · 2.38 KB
/
vite.config.js
File metadata and controls
66 lines (64 loc) · 2.38 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
65
66
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [react()],
server: {
proxy: {
// Proxy /api/rpc to Alchemy in development
'/api/rpc': {
target: env.RPC_URL,
changeOrigin: true,
rewrite: (path) => '', // Remove /api/rpc prefix, send directly to RPC
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
if (req.method === 'POST') {
proxyReq.setHeader('Content-Type', 'application/json');
}
});
},
},
// Proxy /api/subgraph to Goldsky in development
'/api/subgraph': {
target: env.GOLDSKY_SUBGRAPH_URL,
changeOrigin: true,
rewrite: (path) => '', // Remove /api/subgraph prefix, send directly to Goldsky
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
// Add authentication header using server-side env var
const token = env.GOLDSKY_API_TOKEN;
if (token) {
proxyReq.setHeader('Authorization', `Bearer ${token}`);
}
// Ensure content-type is set
if (req.method === 'POST') {
proxyReq.setHeader('Content-Type', 'application/json');
}
});
},
},
// Proxy /api/mon-price to Alchemy Price API in development
'/api/mon-price': {
target: 'https://api.g.alchemy.com',
changeOrigin: true,
rewrite: (path) => '/prices/v1/tokens/by-symbol?symbols=MON',
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
// Extract API key from RPC_URL
const rpcUrl = env.RPC_URL || '';
const match = rpcUrl.match(/\/v2\/([a-zA-Z0-9_-]+)$/);
const apiKey = match ? match[1] : '';
if (apiKey) {
proxyReq.setHeader('Authorization', `Bearer ${apiKey}`);
}
proxyReq.setHeader('Accept', 'application/json');
});
},
},
},
},
}
})