diff --git a/types/cors/cors-tests.ts b/types/cors/cors-tests.ts
index 83975549c7..ed4cd77213 100644
--- a/types/cors/cors-tests.ts
+++ b/types/cors/cors-tests.ts
@@ -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'));
+ }
+}))
diff --git a/types/cors/index.d.ts b/types/cors/index.d.ts
index ab8ba2ed2d..bc7a567fc7 100644
--- a/types/cors/index.d.ts
+++ b/types/cors/index.d.ts
@@ -1,12 +1,9 @@
// Type definitions for cors 2.8
// Project: https://github.com/troygoode/node-cors/
-// Definitions by: Mihhail Lapushkin
+// Definitions by: Alan Plum
// 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;