mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
[cors] Add delegate function and change owner (#25177)
* Add cors delegate function * Remove Mihhail Lapushkin as per his wishes
This commit is contained in:
committed by
Ryan Cavanaugh
parent
afb4ff4cfb
commit
54a59cd8f0
@@ -47,4 +47,11 @@ app.use(cors({
|
||||
}
|
||||
}
|
||||
}));
|
||||
app.use(cors((req, cb) => {
|
||||
if (req.query.trusted) {
|
||||
cb(null, {origin: 'http://example.com', credentials: true});
|
||||
} else {
|
||||
cb(new Error('Not trusted'));
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
13
types/cors/index.d.ts
vendored
13
types/cors/index.d.ts
vendored
@@ -1,12 +1,9 @@
|
||||
// Type definitions for cors 2.8
|
||||
// Project: https://github.com/troygoode/node-cors/
|
||||
// Definitions by: Mihhail Lapushkin <https://github.com/mihhail-lapushkin/>
|
||||
// Definitions by: Alan Plum <https://github.com/pluma>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
|
||||
|
||||
|
||||
import express = require('express');
|
||||
|
||||
type CustomOrigin = (
|
||||
@@ -25,7 +22,13 @@ declare namespace e {
|
||||
preflightContinue?: boolean;
|
||||
optionsSuccessStatus?: number;
|
||||
}
|
||||
type CorsOptionsDelegate = (
|
||||
req: express.Request,
|
||||
callback: (err: Error | null, options?: CorsOptions) => void
|
||||
) => void;
|
||||
}
|
||||
|
||||
declare function e(options?: e.CorsOptions): express.RequestHandler;
|
||||
declare function e(
|
||||
options?: e.CorsOptions | e.CorsOptionsDelegate
|
||||
): express.RequestHandler;
|
||||
export = e;
|
||||
|
||||
Reference in New Issue
Block a user