mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
enhanced cors package, up to v2.8 (#13593)
* enhanced cors package, up to v2.8 * added missing test cases
This commit is contained in:
+38
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
Vendored
+11
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user