cors-express
Advanced tools
Comparing version 0.1.0 to 0.2.0
38
index.js
@@ -1,37 +0,1 @@ | ||
var _ = require('lodash'); | ||
module.exports = function(options) { | ||
options = _.merge({ | ||
options : function(req, res, next){ | ||
if (req.method == 'OPTIONS') { | ||
res.status(200).end(); | ||
} else { | ||
next(); | ||
} | ||
}, | ||
allow : { | ||
origin: '*', | ||
methods: 'GET,PATCH,PUT,POST,DELETE,HEAD,OPTIONS', | ||
headers: 'Content-Type, Authorization, Content-Length, X-Requested-With, X-HTTP-Method-Override' | ||
}, | ||
expose :{ | ||
headers : null | ||
} | ||
}, options); | ||
return function(req, res, next) { | ||
res.setHeader('Access-Control-Allow-Origin', options.allow.origin); | ||
res.setHeader('Access-Control-Allow-Methods', options.allow.methods); | ||
res.setHeader('Access-Control-Allow-Headers', options.allow.headers); | ||
if (options.expose.headers) { | ||
res.setHeader('Access-Control-Expose-Headers', options.expose.headers); | ||
} | ||
if (req.method == 'OPTIONS' && options.options) { | ||
return options.options(req, res, next); | ||
} else { | ||
return next(); | ||
} | ||
}; | ||
}; | ||
module.exports = require('./lib/express-cors'); |
{ | ||
"name": "cors-express", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Middleware to control CORS in an Express app", | ||
@@ -9,5 +9,3 @@ "main": "index.js", | ||
"dev": "clear && export NODE_ENV=development && npm install && npm update && ./node_modules/.bin/nodemon", | ||
"devtest": "clear && export NODE_ENV=development && npm install && ./node_modules/.bin/mocha --reporter spec", | ||
"start": "clear && export NODE_ENV=production && npm install && nodemon -e js,json,hbs", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "clear && export NODE_ENV=development && npm install && ./node_modules/.bin/mocha --reporter spec" | ||
}, | ||
@@ -18,2 +16,5 @@ "repository": { | ||
}, | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"keywords": [ | ||
@@ -36,8 +37,13 @@ "cors", | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.9.1" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.7.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"express": "^4.13.4", | ||
"mocha": "^2.3.3", | ||
"nodemon": "^1.7.1", | ||
"npm-check-updates": "^2.6.1", | ||
"supertest": "^1.1.0" | ||
} | ||
} |
@@ -1,2 +0,72 @@ | ||
# express-cors | ||
# cors-express | ||
Middleware to control CORS in an Express app | ||
## Installation | ||
The best way to install it is using **npm** | ||
```sh | ||
npm install cors-express --save | ||
``` | ||
## Loading | ||
```js | ||
var cors = require('cors-express'); | ||
``` | ||
## Initialization and Usage | ||
```js | ||
var app = express(), | ||
options = {}; | ||
app.use(cors(options)); | ||
``` | ||
## Options | ||
```json | ||
{ | ||
allow : { | ||
origin: '*', | ||
methods: 'GET,PATCH,PUT,POST,DELETE,HEAD,OPTIONS', | ||
headers: 'Content-Type, Authorization, Content-Length, X-Requested-With, X-HTTP-Method-Override' | ||
}, | ||
expose :{ | ||
headers : null | ||
}, | ||
max : { | ||
age : null | ||
}, | ||
options : function(req, res, next){ | ||
if (req.method == 'OPTIONS') { | ||
res.status(200).end(); | ||
} else { | ||
next(); | ||
} | ||
}, | ||
specials : { | ||
powered : null | ||
} | ||
``` | ||
### Options | ||
This method override the normal use of the "option" method and return OK with seted CORS headers | ||
### Specials | ||
#### Powered | ||
Can change the "x-powered-by" header. You can use: | ||
* **null** show original header: "Express" | ||
* **false** doesn't show the header: "Express | ||
* **string** show your own string | ||
## Support | ||
This plugin is proudly supported by [Kubide](http://kubide.es/) [hi@kubide.es](mailto:hi@kubide.es) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
33694
15
150
1
73
6
1