Local dev proxy working with all base modules
This commit is contained in:
		
							parent
							
								
									e9f34ee328
								
							
						
					
					
						commit
						d52ead88ce
					
				@ -1,17 +1,13 @@
 | 
			
		||||
 | 
			
		||||
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';
 | 
			
		||||
 | 
			
		||||
let backendConfigContent;
 | 
			
		||||
let frontendConfigContent;
 | 
			
		||||
let configContent;
 | 
			
		||||
 | 
			
		||||
// Read frontend config 
 | 
			
		||||
try {
 | 
			
		||||
    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`);
 | 
			
		||||
} catch (e) {
 | 
			
		||||
    console.log(e);
 | 
			
		||||
@ -22,50 +18,88 @@ try {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Read backend config
 | 
			
		||||
try {
 | 
			
		||||
    const rawConfig = fs.readFileSync(BACKEND_CONFIG_FILE_NAME);
 | 
			
		||||
    backendConfigContent = JSON.parse(rawConfig);
 | 
			
		||||
    console.log(`${BACKEND_CONFIG_FILE_NAME} file found, using provided config`);
 | 
			
		||||
} catch (e) {
 | 
			
		||||
    console.log(e);
 | 
			
		||||
    if (e.code !== 'ENOENT') {
 | 
			
		||||
      throw new Error(e);
 | 
			
		||||
  } else {
 | 
			
		||||
      console.log(`${BACKEND_CONFIG_FILE_NAME} file not found, using default config`);
 | 
			
		||||
let PROXY_CONFIG = [];
 | 
			
		||||
 | 
			
		||||
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/"
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  ]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user