forked from onecx/onecx-theme-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.conf.js
32 lines (30 loc) · 848 Bytes
/
proxy.conf.js
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
/**
* Used in local environment:
* Request proxy to rewrite URLs and prevent CORS errors
*/
const logFn = function (req, res) {
//console.log(new Date().toISOString() + `: bypassing ${req.method} ${req.url} `)
}
const onProxyRes = function (proxyRes, req, res) {
logFn(req, res)
if (req.method.toUpperCase() === 'OPTIONS') {
res.setHeader('Allow', 'GET, POST, HEAD, PUT, DELETE, OPTIONS')
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', '*')
res.setHeader('Access-Control-Allow-Headers', '*')
return res.send('')
}
}
const PROXY_CONFIG = {
'/bff': {
target: 'http://onecx-theme-bff',
secure: false,
pathRewrite: {
'^.*/bff': ''
},
changeOrigin: true,
logLevel: 'debug',
onProxyRes: onProxyRes
}
}
module.exports = PROXY_CONFIG