Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
improve type of ignore option of middleware (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed May 23, 2020
1 parent cb2c4ca commit b80346e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions runtime/src/server/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Handler, Req, Res } from './types';
import { get_server_route_handler } from './get_server_route_handler';
import { get_page_handler } from './get_page_handler';

type IgnoreValue = Array | RegExp | function | string;

export default function middleware(opts: {
session?: (req: Req, res: Res) => any,
ignore?: any
ignore?: IgnoreValue
} = {}) {
const { session, ignore } = opts;

Expand Down Expand Up @@ -65,7 +67,7 @@ export default function middleware(opts: {
].filter(Boolean));
}

export function compose_handlers(ignore: any, handlers: Handler[]): Handler {
export function compose_handlers(ignore: IgnoreValue, handlers: Handler[]): Handler {
const total = handlers.length;

function nth_handler(n: number, req: Req, res: Res, next: () => void) {
Expand All @@ -87,7 +89,7 @@ export function compose_handlers(ignore: any, handlers: Handler[]): Handler {
};
}

export function should_ignore(uri: string, val: any) {
export function should_ignore(uri: string, val: IgnoreValue) {
if (Array.isArray(val)) return val.some(x => should_ignore(uri, x));
if (val instanceof RegExp) return val.test(uri);
if (typeof val === 'function') return val(uri);
Expand Down

0 comments on commit b80346e

Please sign in to comment.