forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug-proxy
executable file
·37 lines (28 loc) · 1.21 KB
/
debug-proxy
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
#!/usr/bin/env node
// This proxy is useful for debugging frontend issues on deployed instances of
// Metabase. You can use the frontend of a local insance in conjunction with them
// backend of a deployed instance.
var http = require("http");
var httpProxy = require("http-proxy");
var url = require("url");
var backendTarget = process.argv[2] || "https://staging.metabase.com/";
var frontendTarget = process.argv[3] || "http://127.0.0.1:3000/";
var backendHost = url.parse(backendTarget).host;
var frontendHost = url.parse(frontendTarget).host;
var listenPort = parseInt(process.argv[4] || "3001");
var proxy = httpProxy.createProxyServer({ secure: false });
var server = http.createServer(function(req, res) {
if (/^\/app\//.test(req.url)) {
console.log("FRONTEND: " + req.url);
req.headers.host = frontendHost;
proxy.web(req, res, { target: frontendTarget });
} else {
console.log("BACKEND: " + req.url);
req.headers.host = backendHost;
proxy.web(req, res, { target: backendTarget });
}
});
console.log("frontend target: " + frontendTarget);
console.log("backend target: " + backendTarget);
console.log("listening port: " + listenPort);
server.listen(listenPort);