Last active
January 23, 2025 23:42
-
-
Save adjeim/a2ddb5214c92ce5d708fb0a3d6f073f6 to your computer and use it in GitHub Desktop.
Revisions
-
adjeim renamed this gist
Mar 31, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
adjeim renamed this gist
Mar 31, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
adjeim renamed this gist
Mar 31, 2021 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ 1. Install `cors` package and its TypeScript types: ```bash npm install cors -
adjeim created this gist
Mar 31, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ # CORS Cheat Sheet for Express + TypeScript 1. Install `cors` package and its TypeScript types: ```bash npm install cors npm install --save-dev @types/cors ``` 2. Update the entry point of your Express app to allow your server to use `cors` middleware. Configure your CORS options with the origins you would like to allow. ```javascript import express from 'express'; import cors from 'cors'; const app = express(); // Add a list of allowed origins. // If you have more origins you would like to add, you can add them to the array below. const allowedOrigins = ['http://localhost:3000']; const options: cors.CorsOptions = { origin: allowedOrigins }; // Then pass these options to cors: app.use(cors(options)); app.use(express.json()); app.listen(5000, () => { console.log('Express server listening on port 5000'); }); ```