mirror of
https://github.com/mempool/mempool.git
synced 2025-03-15 12:20:28 +01:00
Local dev proxy working with all base modules
This commit is contained in:
parent
1ada92f03e
commit
006ed39bf2
1 changed files with 83 additions and 49 deletions
|
@ -1,17 +1,13 @@
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
let PROXY_CONFIG = require('./proxy.conf.js');
|
|
||||||
const BACKEND_CONFIG_FILE_NAME = '../backend/mempool-config.json';
|
|
||||||
const FRONTEND_CONFIG_FILE_NAME = 'mempool-frontend-config.json';
|
const FRONTEND_CONFIG_FILE_NAME = 'mempool-frontend-config.json';
|
||||||
|
|
||||||
let backendConfigContent;
|
let configContent;
|
||||||
let frontendConfigContent;
|
|
||||||
|
|
||||||
// Read frontend config
|
// Read frontend config
|
||||||
try {
|
try {
|
||||||
const rawConfig = fs.readFileSync(FRONTEND_CONFIG_FILE_NAME);
|
const rawConfig = fs.readFileSync(FRONTEND_CONFIG_FILE_NAME);
|
||||||
frontendConfigContent = JSON.parse(rawConfig);
|
configContent = JSON.parse(rawConfig);
|
||||||
console.log(`${FRONTEND_CONFIG_FILE_NAME} file found, using provided config`);
|
console.log(`${FRONTEND_CONFIG_FILE_NAME} file found, using provided config`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -22,50 +18,88 @@ try {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read backend config
|
let PROXY_CONFIG = [];
|
||||||
try {
|
|
||||||
const rawConfig = fs.readFileSync(BACKEND_CONFIG_FILE_NAME);
|
if (configContent && configContent.BASE_MODULE === 'liquid') {
|
||||||
backendConfigContent = JSON.parse(rawConfig);
|
PROXY_CONFIG.push(...[
|
||||||
console.log(`${BACKEND_CONFIG_FILE_NAME} file found, using provided config`);
|
{
|
||||||
} catch (e) {
|
context: ['/liquid/api/v1/**'],
|
||||||
console.log(e);
|
target: `http://localhost:8999`,
|
||||||
if (e.code !== 'ENOENT') {
|
secure: false,
|
||||||
throw new Error(e);
|
ws: true,
|
||||||
} else {
|
changeOrigin: true,
|
||||||
console.log(`${BACKEND_CONFIG_FILE_NAME} file not found, using default config`);
|
proxyTimeout: 30000,
|
||||||
|
pathRewrite: {
|
||||||
|
"^/liquid": ""
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
context: ['/liquid/api/**'],
|
||||||
|
target: `http://localhost:8999`,
|
||||||
|
secure: false,
|
||||||
|
changeOrigin: true,
|
||||||
|
proxyTimeout: 30000,
|
||||||
|
pathRewrite: {
|
||||||
|
"^/liquid/api/": "/api/v1/"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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/"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROXY_CONFIG.push(...[
|
||||||
|
{
|
||||||
|
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/"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
]);
|
||||||
|
|
||||||
// Remove the "/api/**" entry from the default proxy config
|
|
||||||
let localDevContext = PROXY_CONFIG[0].context
|
|
||||||
|
|
||||||
localDevContext.splice(PROXY_CONFIG[0].context.indexOf('/api/**'), 1);
|
|
||||||
|
|
||||||
PROXY_CONFIG[0].context = localDevContext;
|
|
||||||
|
|
||||||
// Change all targets to localhost
|
|
||||||
PROXY_CONFIG.map(conf => conf.target = "http://localhost:8999");
|
|
||||||
|
|
||||||
// Add rules for local backend
|
|
||||||
if (backendConfigContent) {
|
|
||||||
PROXY_CONFIG.push({
|
|
||||||
context: ['/api/v1/**'],
|
|
||||||
target: `http://localhost:8999`,
|
|
||||||
secure: false,
|
|
||||||
changeOrigin: true,
|
|
||||||
proxyTimeout: 30000
|
|
||||||
});
|
|
||||||
PROXY_CONFIG.push({
|
|
||||||
context: ['/api/**'],
|
|
||||||
target: `http://localhost:8999`,
|
|
||||||
secure: false,
|
|
||||||
changeOrigin: true,
|
|
||||||
proxyTimeout: 30000,
|
|
||||||
pathRewrite: {
|
|
||||||
"^/api/": "/api/v1/"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(PROXY_CONFIG);
|
console.log(PROXY_CONFIG);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue