Skip to content

Commit

Permalink
released v4.3.0-next.4 - adding types to cors
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Mar 25, 2024
1 parent 8357b10 commit f8ff61c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itty-router",
"version": "4.3.0-next.3",
"version": "4.3.0-next.4",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
Expand Down
10 changes: 10 additions & 0 deletions src/cors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IRequest } from 'IttyRouter'

export type CorsOptions = {
credentials?: true
origin?: boolean | string | string[] | RegExp | ((origin: string) => string | void)
Expand All @@ -7,6 +9,14 @@ export type CorsOptions = {
exposeHeaders?: string | string[]
}

export type Preflight = (request: IRequest) => Response | void
export type Corsify = (response: Response, request?: IRequest) => Response

export type CorsPair = {
preflight: Preflight
corsify: Corsify
}

// Create CORS function with default options.
export const cors = (options: CorsOptions = {}) => {
// Destructure and set defaults for options.
Expand Down

0 comments on commit f8ff61c

Please sign in to comment.