forked from sdhealthconnect/leap-fhir-ces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (25 loc) · 823 Bytes
/
app.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");
const morgan = require("morgan");
const { createProxyMiddleware } = require("http-proxy-middleware");
const logger = require("./lib/logger");
const FHIRProxy = require("./controllers/FHIRProxy");
const FHIR_SERVER_BASE = process.env.FHIR_SERVER_BASE;
const app = express();
app.set("trust proxy", true);
//middlewares
process.env.NODE_ENV === "production" || app.use(morgan("dev"));
const proxyOptions = {
target: FHIR_SERVER_BASE,
onProxyRes: FHIRProxy.onProxyRes,
onProxyReq: FHIRProxy.onProxyReq,
xfwd: true,
changeOrigin: true,
selfHandleResponse: true
};
//this is a requirement for gcp
app.get("/_ah/start", (req, res) => {
res.sendStatus(404);
});
logger.info(`Starting the proxy.`);
app.use("/", createProxyMiddleware(proxyOptions));
module.exports = app;