Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
expand cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouncey committed Dec 16, 2017
1 parent 2c2885c commit fad93b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
3 changes: 1 addition & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ app.use(bodyParser.json());
app.set('views', __dirname +'/views');
app.set('view engine', 'pug');


// this route is to be removed when we update guides to use the v1 route
// this route is to be removed when we update guides and FCCSearchBar to use the v1 route
app.get('/search', cors, (req, res) => {
const { q: query } = req.query;
Observable.fromPromise(findTheThings(query))
Expand Down
17 changes: 5 additions & 12 deletions server/middleware/cors.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
const cors = require('cors');

const whitelist = [
'http://guide.freecodecamp.org',
'https://guide.freecodecamp.org',
'http://news.freecodecamp.org',
'https://news.freecodecamp.org',
'http://localhost:8000'
/(\.|https:\/\/)freecodecamp\.org/, // freecodecamp.org and any subdomain of
/\.netlify\.com/, // deploy previews
'http://localhost:3000', // fcc dev
'http://localhost:8000' // guides dev
];
const corsOptions = {
origin: function (origin, callback) {
if (whitelist.includes(origin)) {
callback(null, true);
} else {
callback(new Error('The request is not from an authorised origin'));
}
},
origin: whitelist,
optionsSuccessStatus: 200
};
exports.cors = cors;
Expand Down

0 comments on commit fad93b0

Please sign in to comment.