1.3 Install CORS & implement via app.js

Cross Origin Resource Sharing

Will Barnes
Jul 6, 2017 · 1 min read

wb todoMVC Master >> 1.3 install CORS & imple…

Update 7/19

OpenAPI3 (aka swagger3) is just about ready for official release. This means steps 1.1–1.x will need to be rewritten soon. The folks over at swagger-api are working hard updating the many swag tools to work with the latest spec.


Open terminal and navigate to project

$ cd ~/Sites/swag/todo-api

Install CORS in project

$ npm install cors --save

Open app.js

$ open app.js

Implement CORS in app.js referencing lines 10 & 27 below

// code
line 10: var cors = require('cors');
// code
line 27: app.use(cors());
// code

Gotchas (restart required?)

You may find that you have to manually restart both your swagger editor & swagger server in mock mode to prevent bugs moving forward.

Tutorial Navigation

The master tutorial doc is located here: WB todoMVC MASTER

Previous Step: 1.2 run swagger editor & server in mock mode

Next Step: 1.4 define TODO data model and define GET endpoint.

Will Barnes

Written by

An intelligent fool, stubbornly optimistic, relentlessly persistent, tech-cofounder at cProject

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade