🔧 CORS proxy server

This commit is contained in:
2021-11-24 10:23:48 -08:00
parent ce5ad3575e
commit 485273da21
6 changed files with 63 additions and 6 deletions

View File

@@ -2,9 +2,11 @@ import express, { Request, Response, Router, Express } from "express";
import bodyParser from "body-parser";
import router from "./route";
import path from "path";
import cors_proxy from "cors-anywhere";
// call express
const app: Express = express(); // define our app using express
const host = process.env.HOST || "0.0.0.0";
// configure app to use bodyParser for
// Getting data from body of requests
@@ -12,6 +14,7 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const port: number = Number(process.env.PORT) || 8050; // set our port
const proxyPort = 8050; // set our port
app.get("/", (req: Request, res: Response) => {
console.log("sending index.html");
@@ -27,6 +30,20 @@ app.use("/api", routes);
app.use(express.static("dist"));
app.use(express.static("public"));
app.listen(port);
// app.listen(port);
// console.log(`Server is listening on ${port}`);
console.log(`Server is listening on ${port}`);
cors_proxy
.createServer({
originWhitelist: [], // Allow all origins
requireHeader: ["origin", "x-requested-with"],
removeHeaders: ["cookie", "cookie2"],
})
.listen(port, host, function () {
console.log(
"ThreeTwo! Express server with CORS Anywhere running on " +
host +
":" +
proxyPort,
);
});