forked from sk-musik-production-inc/mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.conf.parameterized.js
More file actions
36 lines (29 loc) · 1.02 KB
/
proxy.conf.parameterized.js
File metadata and controls
36 lines (29 loc) · 1.02 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
const fs = require('fs');
const PROXY_CONFIG = require('./proxy.conf');
const addApiKeyHeader = (proxyReq, req, res) => {
if (process.env.MEMPOOL_CI_API_KEY) {
proxyReq.setHeader('X-Mempool-Auth', process.env.MEMPOOL_CI_API_KEY);
}
};
PROXY_CONFIG.forEach((entry) => {
const mempoolHostname = process.env.MEMPOOL_HOSTNAME
? process.env.MEMPOOL_HOSTNAME
: 'mempool.space';
const liquidHostname = process.env.LIQUID_HOSTNAME
? process.env.LIQUID_HOSTNAME
: 'liquid.network';
entry.target = entry.target.replace('mempool.space', mempoolHostname);
entry.target = entry.target.replace('liquid.network', liquidHostname);
if (entry.onProxyReq) {
const originalProxyReq = entry.onProxyReq;
entry.onProxyReq = (proxyReq, req, res) => {
originalProxyReq(proxyReq, req, res);
if (process.env.MEMPOOL_CI_API_KEY) {
proxyReq.setHeader('X-Mempool-Auth', process.env.MEMPOOL_CI_API_KEY);
}
};
} else {
entry.onProxyReq = addApiKeyHeader;
}
});
module.exports = PROXY_CONFIG;