Skip to content

Commit

Permalink
fix: Enable CORS from all origins on server
Browse files Browse the repository at this point in the history
Previously we left CORS to default values so it was easy to hit CORS errors from React apps, which isn't part of the point of this assignment.
  • Loading branch information
neil-hughes committed Feb 7, 2023
1 parent 7413dbc commit e82a88f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/express": "^4.17.14",
"@types/node": "^18.11.18",
"concurrently": "^7.6.0",
"cors": "^2.8.5",
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"express": "^4.18.2",
Expand All @@ -34,5 +35,8 @@
"bugs": {
"url": "https://github.com/techreturners/lm-code-intro-react-router-fakelandia/issues"
},
"homepage": "https://github.com/techreturners/lm-code-intro-react-router-fakelandia#readme"
"homepage": "https://github.com/techreturners/lm-code-intro-react-router-fakelandia#readme",
"devDependencies": {
"@types/cors": "^2.8.13"
}
}
5 changes: 4 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as express from 'express';

import * as cors from 'cors';
import { Server } from 'http';
import { initialiseRoutes } from './routes/routes';
import { printNewLine } from './helpers/helpers';
Expand All @@ -18,6 +18,9 @@ try {
console.log('👉 Enabling URL-Encoded middleware...');
app.use(express.urlencoded({ extended: true }));

console.log('👉 Enabling CORS...');
app.use(cors());

initialiseRoutes(app);

const server = app
Expand Down

0 comments on commit e82a88f

Please sign in to comment.