forked from HISP-Uganda/cqi-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupProxy.js
34 lines (30 loc) · 882 Bytes
/
setupProxy.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
const express = require("express");
var cors = require("cors");
const { createProxyMiddleware } = require("http-proxy-middleware");
let sessionCookie = "";
const onProxyReq = (proxyReq) => {
if (sessionCookie) {
proxyReq.setHeader("cookie", sessionCookie);
}
};
const onProxyRes = (proxyRes) => {
const proxyCookie = proxyRes.headers["set-cookie"];
if (proxyCookie) {
sessionCookie = proxyCookie;
}
};
// proxy middleware options
const options = {
target: "https://cqi.health.go.ug", // target host
onProxyReq,
onProxyRes,
changeOrigin: true, // needed for virtual hosted sites
auth: undefined,
logLevel: "debug",
};
// create the proxy (without context)
const exampleProxy = createProxyMiddleware(options);
const app = express();
app.use(cors({ credentials: true, origin: "http://localhost:3000" }));
app.use("/", exampleProxy);
app.listen(3002);