diff --git a/types/roads/index.d.ts b/types/roads/index.d.ts index 55028403b6..727bc1c819 100644 --- a/types/roads/index.d.ts +++ b/types/roads/index.d.ts @@ -11,6 +11,23 @@ export type Keys = string; export type Option = {[k in Keys]: any}; +/** + * @param validOrigins An array of origin urls that can send requests to this API + * @param supportsCredentials A boolean, true if you want this endpoint to receive cookies + * @param responseHeaders An array of valid HTTP response headers + * @param requestHeaders An array of valid HTTP request headers + * @param validMethods An array of valid HTTP methods + * @param cacheMaxAge The maximum age to cache the cors information + */ +export interface Cors { + validOrigins: string[]; + supportsCredentials?: boolean; + responseHeaders?: string[]; + requestHeaders?: string[]; + validMethods?: string[]; + cacheMaxAge?: number; +} + /** * @param method The HTTP method that was provided to the request * @param url The URL that was provided to the request @@ -126,10 +143,9 @@ export namespace middleware { /** * Middleware to Apply proper cors headers - * @param allow_origins Either * to allow all origins, or an explicit list of valid origins - * @param allow_headers A white list of headers that the client is allowed to send in their requests + * @param options Cors options */ - function cors(allow_origins: string | string[], allow_headers?: string[]): any; + function cors(options: Cors): any; /** * Translate the request body into a usable value diff --git a/types/roads/roads-tests.ts b/types/roads/roads-tests.ts index 6914c3d218..9bc7f4e818 100644 --- a/types/roads/roads-tests.ts +++ b/types/roads/roads-tests.ts @@ -3,7 +3,14 @@ import { build, Road, middleware, integrations, Response, HttpError, PJAX } from const road = new Road(); const router = new middleware.SimpleRouter(road); -road.use(middleware.cors("*")); +road.use(middleware.cors({ + requestHeaders: ["content-type"], + responseHeaders: ["content-type"], + supportsCredentials: true, + validOrigins: ["http://localhost:8080"], + validMethods: ["GET", "POST"], + cacheMaxAge: 4 +})); road.use(middleware.killSlash);