From 43fd13d225bf4e97d5d2d38fdb893cf3b8d5441a Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Sun, 14 May 2017 17:41:23 -0400 Subject: [PATCH 1/3] Make CORS a variable again This fixes the 'Property 'CORS' does not exist' problem. --- types/restify/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/restify/index.d.ts b/types/restify/index.d.ts index bb0db64140..5a6b692570 100644 --- a/types/restify/index.d.ts +++ b/types/restify/index.d.ts @@ -595,7 +595,7 @@ export function auditLogger(options: { log: any }): (req: Request, res: Response export function fullResponse(): RequestHandler; // tslint:disable-next-line no-var export var defaultResponseHeaders: any; -export interface CORS { +export const CORS: { (cors?: { origins?: string[]; credentials?: boolean; @@ -604,7 +604,7 @@ export interface CORS { origins: string[]; ALLOW_HEADERS: string[]; credentials: boolean; -} +}; export const pre: { pause(): RequestHandler; From 580597113e19bb5c4d67a9824836f49b13b5a305 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Sun, 14 May 2017 21:20:17 -0400 Subject: [PATCH 2/3] Add test for restify.CORS() --- types/restify/restify-tests.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/restify/restify-tests.ts b/types/restify/restify-tests.ts index 34db48ba0a..15eb8eb868 100644 --- a/types/restify/restify-tests.ts +++ b/types/restify/restify-tests.ts @@ -254,6 +254,11 @@ server.use(restify.queryParser()); server.use(restify.jsonp()); server.use(restify.gzipResponse()); server.use(restify.bodyParser()); +server.use(restify.CORS({ + origins: ['https://foo.com', 'http://bar.com', 'http://baz.com:8081'], + credentials: true, + headers: ['x-foo'] +})); server.use(restify.throttle({ burst: 100, rate: 50, From e5ce007af582343ca9d207145a1b0732f0d0ee7f Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 18 May 2017 09:26:36 -0400 Subject: [PATCH 3/3] Hide static fields and make CORS a pure function --- types/restify/index.d.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/types/restify/index.d.ts b/types/restify/index.d.ts index 5a6b692570..6074ce8284 100644 --- a/types/restify/index.d.ts +++ b/types/restify/index.d.ts @@ -595,16 +595,13 @@ export function auditLogger(options: { log: any }): (req: Request, res: Response export function fullResponse(): RequestHandler; // tslint:disable-next-line no-var export var defaultResponseHeaders: any; -export const CORS: { - (cors?: { - origins?: string[]; - credentials?: boolean; - headers?: string[]; - }): RequestHandler; - origins: string[]; - ALLOW_HEADERS: string[]; - credentials: boolean; -}; + +export function CORS(options?: CORSOptions): RequestHandler; +export interface CORSOptions { + origins?: string[]; + credentials?: boolean; + headers?: string[]; +} export const pre: { pause(): RequestHandler;