[cors] Add delegate function and change owner (#25177)

* Add cors delegate function

* Remove Mihhail Lapushkin as per his wishes
This commit is contained in:
Alan Plum
2018-04-23 17:00:09 +02:00
committed by Ryan Cavanaugh
parent afb4ff4cfb
commit 54a59cd8f0
2 changed files with 15 additions and 5 deletions

View File

@@ -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
View File

@@ -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;