Skip to content

Commit 54a59cd

Browse files
plumaRyanCavanaugh
authored andcommitted
[cors] Add delegate function and change owner (#25177)
* Add cors delegate function * Remove Mihhail Lapushkin as per his wishes
1 parent afb4ff4 commit 54a59cd

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

types/cors/cors-tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ app.use(cors({
4747
}
4848
}
4949
}));
50+
app.use(cors((req, cb) => {
51+
if (req.query.trusted) {
52+
cb(null, {origin: 'http://example.com', credentials: true});
53+
} else {
54+
cb(new Error('Not trusted'));
55+
}
56+
}))
5057

types/cors/index.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Type definitions for cors 2.8
22
// Project: https://github.com/troygoode/node-cors/
3-
// Definitions by: Mihhail Lapushkin <https://github.com/mihhail-lapushkin/>
3+
// Definitions by: Alan Plum <https://github.com/pluma>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
55
// TypeScript Version: 2.2
66

7-
8-
9-
107
import express = require('express');
118

129
type CustomOrigin = (
@@ -25,7 +22,13 @@ declare namespace e {
2522
preflightContinue?: boolean;
2623
optionsSuccessStatus?: number;
2724
}
25+
type CorsOptionsDelegate = (
26+
req: express.Request,
27+
callback: (err: Error | null, options?: CorsOptions) => void
28+
) => void;
2829
}
2930

30-
declare function e(options?: e.CorsOptions): express.RequestHandler;
31+
declare function e(
32+
options?: e.CorsOptions | e.CorsOptionsDelegate
33+
): express.RequestHandler;
3134
export = e;

0 commit comments

Comments
 (0)