cors: adding cors middleware to express

This commit is contained in:
@wwwjim 2020-08-17 15:07:31 -07:00
parent 60a23a87e3
commit 8ed70e615c
2 changed files with 7 additions and 1 deletions

View File

@ -51,6 +51,7 @@
"chart.js": "^2.9.3",
"chartkick": "^3.2.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"fs-extra": "^9.0.1",

View File

@ -9,6 +9,7 @@ import * as AnalyticsManager from "~/node_common/managers/analytics";
import express from "express";
import next from "next";
import compression from "compression";
import cors from "cors";
const app = next({
dev: !Environment.IS_PRODUCTION,
@ -21,6 +22,8 @@ const handler = app.getRequestHandler();
app.prepare().then(async () => {
const server = express();
app.use(cors());
if (Environment.IS_PRODUCTION) {
server.use(compression());
}
@ -119,7 +122,9 @@ app.prepare().then(async () => {
}
return app.render(req, res, "/_/slate", {
slate: JSON.parse(JSON.stringify({ ...slate, ownername: req.params.username })),
slate: JSON.parse(
JSON.stringify({ ...slate, ownername: req.params.username })
),
});
});