-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
53 lines (43 loc) · 1.38 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// change process' current dir
process.chdir(__dirname);
// load environment variables from `.env`
require("dotenv-defaults").config();
const path = require("path"),
express = require("express"),
{ createProxyMiddleware: proxy } = require("http-proxy-middleware"),
chalk = require("chalk"),
logPrefix = chalk.keyword("azure").bgRed(' proxy '),
port = process.env.PORT || 8080;
const app = express();
app.use(express.static(path.resolve(process.env.COMMON_STATIC_PATH)));
app.use("/api", proxy({
target: process.env.API_URL,
logLevel: "error",
changeOrigin: true,
pathRewrite: {"^/api" : ""},
}));
app.use("/dashboard", proxy({
target: process.env.DASHBOARD_URL,
logLevel: "error",
changeOrigin: true
}));
app.use("/", proxy({
target: process.env.FACADE_URL,
logLevel: "error",
changeOrigin: true
}));
app.listen(port, () => {
const clipboardy = require('clipboardy');
clipboardy.writeSync("http://localhost:" + port);
console.log(`${logPrefix} Development proxy running at ${chalk.blue("http://localhost:" + port)} (copied to clipboard)`);
});
// handle errors
process.on("uncaughtException", function (error) {
console.error("uncaughtException");
console.error(error);
});
process.on("unhandledRejection", function (reason, p) {
console.error("unhandledRejection");
console.error(reason);
console.error(p);
});