refactor: Add HttpHandlerInput interface

This commit is contained in:
Matthieu Bosquet
2021-01-02 00:45:32 +00:00
committed by Ruben Verborgh
parent 0bd48f0dc5
commit a73936f522
5 changed files with 15 additions and 11 deletions

View File

@@ -1,9 +1,8 @@
import cors from 'cors';
import type { CorsOptions } from 'cors';
import type { RequestHandler } from 'express';
import type { HttpHandlerInput } from '../HttpHandler';
import { HttpHandler } from '../HttpHandler';
import type { HttpRequest } from '../HttpRequest';
import type { HttpResponse } from '../HttpResponse';
const defaultOptions: CorsOptions = {
origin: (origin: any, callback: any): void => callback(null, origin ?? '*'),
@@ -32,7 +31,7 @@ export class CorsHandler extends HttpHandler {
this.corsHandler = cors({ ...defaultOptions, ...options });
}
public async handle(input: { request: HttpRequest; response: HttpResponse }): Promise<void> {
public async handle(input: HttpHandlerInput): Promise<void> {
return new Promise((resolve): void => {
this.corsHandler(input.request as any, input.response as any, (): void => resolve());
});