Allow disabling of CORS

It is desirable to disable CORS for development purposes in order to
validate same-origin policy and web security concepts. Additionally,
json-server could be used to show proxy concepts.

This change adds a new CLI option `--no-cors` which disables CORS by not
adding the CORS middleware. The change is backwards compatible since the
default behavior, i.e. adding CORS headers is retained.
This commit is contained in:
Ben Ripkens
2016-01-17 08:27:05 +01:00
parent b751cec815
commit c50532dd75
4 changed files with 46 additions and 2 deletions

View File

@ -32,7 +32,9 @@ module.exports = function (opts) {
}
// Enable CORS for all the requests, including static files
arr.push(cors({ origin: true, credentials: true }))
if (!opts.noCors) {
arr.push(cors({ origin: true, credentials: true }))
}
if (process.env.NODE_ENV === 'development') {
// only use in development