enhanced cors package, up to v2.8 (#13593)

* enhanced cors package, up to v2.8

* added missing test cases
This commit is contained in:
James Nail
2017-01-04 13:13:52 -08:00
committed by Andy
parent a218626522
commit 844164f7c0
2 changed files with 49 additions and 6 deletions
+38 -1
View File
@@ -6,5 +6,42 @@ var app = express();
app.use(cors());
app.use(cors({
maxAge: 100,
credentials: true
credentials: true,
optionsSuccessStatus: 200
}));
app.use(cors({
methods: 'GET,POST,PUT',
exposedHeaders: 'Content-Range,X-Content-Range',
allowedHeaders: 'Content-Type,Authorization'
}));
app.use(cors({
methods: ['GET', 'POST', 'PUT', 'DELETE'],
exposedHeaders: ['Content-Range', 'X-Content-Range'],
allowedHeaders: ['Content-Type', 'Authorization']
}));
app.use(cors({
origin: true
}));
app.use(cors({
origin: 'http://example.com'
}));
app.use(cors({
origin: /example\.com$/
}));
app.use(cors({
origin: ['http://example.com', 'http://fakeurl.com']
}));
app.use(cors({
origin: [/example\.com$/, /fakeurl\.com$/]
}));
app.use(cors({
origin: (requestOrigin, cb) => {
try {
var allow = requestOrigin.indexOf('.edu') !== -1;
cb(null, allow);
} catch (err) {
cb(err);
}
}
}));
+11 -5
View File
@@ -1,4 +1,4 @@
// Type definitions for cors
// Type definitions for cors 2.8
// Project: https://github.com/troygoode/node-cors/
// Definitions by: Mihhail Lapushkin <https://github.com/mihhail-lapushkin/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -8,15 +8,21 @@
import express = require('express');
type CustomOrigin = (
requestOrigin: string,
callback: (err: Error, allow?: boolean) => void
) => void;
declare namespace e {
interface CorsOptions {
origin?: any;
methods?: any;
allowedHeaders?: any;
exposedHeaders?: any;
origin?: boolean | string | RegExp | string[] | RegExp[] | CustomOrigin;
methods?: string | string[];
allowedHeaders?: string | string[];
exposedHeaders?: string | string[];
credentials?: boolean;
maxAge?: number;
preflightContinue?: boolean;
optionsSuccessStatus?: number;
}
}