Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Very light weight Express middleware module which makes cross origin resource sharing easy.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

small-cor

Build Status

Very light weight middleware for Express which makes cross origin resource sharing easy.

Installation

npm install small-cor

Sample Usage

var express = require('express');
var app = express();
var smallCOR = require('small-cor');

app.use(smallCOR({
    origin : '*',
    methods : ['GET'],
    headers : ['X-Custom']
}));

app.get('/', function(req, res){
  res.json({message : 'hello'});
});

app.listen(3000);

An HTTP GET request to localhost:3000 will result in HTTP response which contains the following headers:

Access-Control-Allow-Headers:X-Custom
Access-Control-Allow-Methods:GET
Access-Control-Allow-Origin:*

Options

  • origin (string): URI of allowed origin. i.e. '*' or 'http://mysite.com'
  • methods (array): Array of strings containing permitted HTTP verbs i.e. ['GET'] or ['GET','POST']
  • headers (array): Array of strings containing permitted HTTP headers i.e. ['X-Custom'] or ['X-Custom', 'X-PingPong']
  • credentials (bool): Boolean indicating if browser will allow creditials to be sent.
Something went wrong with that request. Please try again.