-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
66 lines (60 loc) · 2.23 KB
/
vite.config.ts
File metadata and controls
66 lines (60 loc) · 2.23 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 } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/rup-api': {
target: process.env.VITE_API_BASE_URL||'http://localhost:5173',
changeOrigin: true,
rewrite: (path) => {
const newPath = path.replace(/^\/rup-api/, '');
console.log(`🔄 Proxy rewrite: ${path} -> ${newPath}`);
return newPath;
},
secure: true,
configure: (proxy, options) => {
proxy.on('error', (err, req, res) => {
console.error('❌ Proxy error:', err.message);
console.error('Request details:', {
url: req.url,
method: req.method,
headers: req.headers
});
});
proxy.on('proxyReq', (proxyReq, req, res) => {
console.log(`🌐 Proxying: ${req.method} ${req.url}`);
console.log(`📡 Target: https://isb.lkpp.go.id${proxyReq.path}`);
// Add headers for CORS
proxyReq.setHeader('Accept', 'application/json');
proxyReq.setHeader('User-Agent', 'Mozilla/5.0 (compatible; RUP-Dashboard/1.0)');
});
proxy.on('proxyRes', (proxyRes, req, res) => {
console.log(`📨 Response: ${proxyRes.statusCode} from ${req.url}`);
// Log response headers for debugging
console.log('Response headers:', {
'content-type': proxyRes.headers['content-type'],
'content-length': proxyRes.headers['content-length'],
'access-control-allow-origin': proxyRes.headers['access-control-allow-origin']
});
// Add CORS headers to response
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
});
}
}
},
// Add CORS configuration
cors: true,
// Increase timeout
hmr: {
timeout: 60000
}
},
// Untuk debugging
define: {
__DEV__: JSON.stringify(true),
}
})