2021-11-15 00:40:45 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const FRONTEND_CONFIG_FILE_NAME = 'mempool-frontend-config.json';
|
|
|
|
|
2022-02-04 22:41:17 +01:00
|
|
|
let configContent;
|
2021-11-15 00:40:45 +01:00
|
|
|
|
|
|
|
// Read frontend config
|
|
|
|
try {
|
|
|
|
const rawConfig = fs.readFileSync(FRONTEND_CONFIG_FILE_NAME);
|
2022-02-04 22:41:17 +01:00
|
|
|
configContent = JSON.parse(rawConfig);
|
2021-11-15 00:40:45 +01:00
|
|
|
console.log(`${FRONTEND_CONFIG_FILE_NAME} file found, using provided config`);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
if (e.code !== 'ENOENT') {
|
|
|
|
throw new Error(e);
|
|
|
|
} else {
|
|
|
|
console.log(`${FRONTEND_CONFIG_FILE_NAME} file not found, using default config`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 22:41:17 +01:00
|
|
|
let PROXY_CONFIG = [];
|
2021-11-15 00:40:45 +01:00
|
|
|
|
2022-02-04 22:41:17 +01:00
|
|
|
if (configContent && configContent.BASE_MODULE === 'liquid') {
|
|
|
|
PROXY_CONFIG.push(...[
|
|
|
|
{
|
|
|
|
context: ['/liquid/api/v1/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/liquid": ""
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/liquid/api/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/liquid/api/": "/api/v1/"
|
|
|
|
},
|
2022-02-22 13:39:53 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/liquidtestnet/api/v1/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/liquidtestnet": ""
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/liquidtestnet/api/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/liquidtestnet/api/": "/api/v1/"
|
|
|
|
},
|
|
|
|
},
|
2022-02-04 22:41:17 +01:00
|
|
|
]);
|
|
|
|
}
|
2021-11-15 00:40:45 +01:00
|
|
|
|
|
|
|
|
2022-02-04 22:41:17 +01:00
|
|
|
if (configContent && configContent.BASE_MODULE === 'bisq') {
|
|
|
|
PROXY_CONFIG.push(...[
|
|
|
|
{
|
|
|
|
context: ['/bisq/api/v1/ws'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/bisq": ""
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/bisq/api/v1/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/bisq/api/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/bisq/api/": "/api/v1/bisq/"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]);
|
2021-11-15 00:40:45 +01:00
|
|
|
}
|
|
|
|
|
2022-02-04 22:41:17 +01:00
|
|
|
PROXY_CONFIG.push(...[
|
2022-04-27 00:52:23 +02:00
|
|
|
{
|
2022-07-06 11:58:06 +02:00
|
|
|
context: ['/testnet/api/v1/lightning/**'],
|
|
|
|
target: `http://localhost:8999`,
|
2022-04-27 00:52:23 +02:00
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
2022-07-06 11:58:06 +02:00
|
|
|
"^/testnet": ""
|
2022-04-27 00:52:23 +02:00
|
|
|
},
|
|
|
|
},
|
2022-02-04 22:41:17 +01:00
|
|
|
{
|
|
|
|
context: ['/api/v1/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: ['/api/**'],
|
|
|
|
target: `http://localhost:8999`,
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
proxyTimeout: 30000,
|
|
|
|
pathRewrite: {
|
|
|
|
"^/api/": "/api/v1/"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2021-11-15 00:40:45 +01:00
|
|
|
console.log(PROXY_CONFIG);
|
|
|
|
|
|
|
|
module.exports = PROXY_CONFIG;
|