-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (29 loc) · 896 Bytes
/
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
require("dotenv").config();
const express = require("express");
const morgan = require("morgan");
const app = express();
const httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer();
// Essential Middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(morgan("tiny"));
app.use((req, res) => {
console.log(req.url);
console.log(req.originalUrl);
console.log(req.headers.host);
const targetUrl = `http://${req.headers.host}`;
console.log("TARGET URL");
console.log(targetUrl);
proxy.web(req, res, { target: targetUrl }, (err) => {
console.error("Proxy Error:", err);
res.status(500).send("Proxy Error");
});
});
app.use("/healthcheck", (req, res) => {
res.send("Server is up and running");
});
const PORT = 9000 || process.env.PORT;
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});