🔧 Several CORS related fixes

This commit is contained in:
2021-11-25 23:47:00 -08:00
parent 95fe37e542
commit 0c01d11b44
6 changed files with 74 additions and 40 deletions

View File

@@ -6,22 +6,32 @@ import path from "path";
// call express
const app: Express = express(); // define our app using express
const port: number = Number(process.env.PORT) || 8050; // set our port
// Configure app to respond with these headers for CORS purposes
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept",
);
next();
});
// configure app to use bodyParser for
// Getting data from body of requests
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const port: number = Number(process.env.PORT) || 8050; // set our port
app.get("/", (req: Request, res: Response) => {
console.log("sending index.html");
res.sendFile(path.resolve(__dirname, "../dist/index.html"));
});
//
// app.get("/", (req: Request, res: Response) => {
// console.log("sending index.html");
// res.sendFile(path.resolve(__dirname, "../dist/index.html"));
// });
// REGISTER ROUTES
// all of the routes will be prefixed with /api
const routes: Router[] = Object.values(router);
app.use("/api", routes);
// const routes: Router[] = Object.values(router);
// app.use("/api", routes);
// Send index.html on root request
app.use(express.static("dist"));