-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (37 loc) · 985 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
34
35
36
37
38
39
40
41
42
43
"use strict";
var express = require("express");
var cors = require("cors");
const { createProxyMiddleware } = require("http-proxy-middleware");
var corsOptions = {
origin: true,
preflightContinue: false,
};
function onProxyRes(proxyRes, req, res) {
delete proxyRes.headers["content-security-policy"];
delete proxyRes.headers["x-frame-options"];
delete proxyRes.headers["x-content-type-options"];
if (req.headers["origin"]) {
proxyRes.headers["Access-Control-Allow-Origin"] = req.headers["origin"];
}
}
var proxyTable = {
"website": "url",
};
var options = {
changeOrigin: true,
target: "https://example.com",
preserveHostHdr: true,
onProxyRes: onProxyRes,
router: proxyTable,
secure: false,
followRedirects: true,
};
var myProxy = createProxyMiddleware(options);
var app = express();
app.options("*", cors(corsOptions));
app.options("*", (req, res) => {
res.send("OK");
});
app.use(myProxy);
app.use("*", cors(corsOptions));
app.listen(3000);