-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathproxy.conf.mjs
More file actions
91 lines (78 loc) · 2.23 KB
/
proxy.conf.mjs
File metadata and controls
91 lines (78 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
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
import {PROXY_TARGET} from "./proxy.const.mjs";
import {customizationConfigOverride} from "./customization_config_override.mjs";
import {deepMerge} from "./proxy-utils.mjs";
const proxyRules = [
{
// redirect external login requests
context: ["/primaws/suprimaExtLogin"],
target: PROXY_TARGET,
changeOrigin: true,
followRedirects: true,
onProxyReq(_proxyReq, req, res) {
res.writeHead(302, { location: PROXY_TARGET + req.url });
},
},
{
context: [
'/custom/*/assets',
'/custom/*/assets/**',
'/nde/custom/*/assets',
'/nde/custom/*/assets/**'
],
target: 'not-needed',
router: (req) => `${req.protocol}://${req.get('host')}`,
changeOrigin: false,
logLevel: 'debug',
pathRewrite: (path) =>
path.replace(/^\/(?:nde\/)?custom\/[^/]+\/assets\/?/, '/assets/'),
},
{
context: ['/primaws/rest/pub/configuration/vid/'],
target: PROXY_TARGET,
secure: true,
changeOrigin: true,
logLevel: 'debug',
selfHandleResponse: true,
onProxyRes(proxyRes, req, res) {
const chunks = [];
proxyRes.on('data', chunk => chunks.push(chunk));
proxyRes.on('end', () => {
try {
const bodyStr = Buffer.concat(chunks).toString('utf8');
const json = JSON.parse(bodyStr);
// MERGE instead of replace to retain unspecified fields
json.customization = deepMerge(json.customization || {}, customizationConfigOverride);
const out = JSON.stringify(json);
res.setHeader('content-type', 'application/json');
res.end(out);
} catch (e) {
res.end(Buffer.concat(chunks));
}
});
}
},
{
context: [
'/nde/custom/**'
],
target: 'not-needed',
router: (req) => {
const url = `${req.protocol}://${req.get('host')}`
console.log(url);
return url;
},
secure: true,
logLevel: 'debug',
pathRewrite: { '^/nde/custom/.*/': '' },
},
{
context: [
'**', '!/nde/custom/**'
],
target: PROXY_TARGET,
secure: true,
changeOrigin: true,
logLevel: 'debug',
}
];
export default proxyRules;