🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

cors-express

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cors-express - npm Package Compare versions

Comparing version

to
0.2.0

.idea/jsLibraryMappings.xml

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