From ac1c685c96e294b1e7f1d507e38bbbb4a59834c7 Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Tue, 19 Mar 2019 14:14:32 +0900 Subject: [PATCH] fix: types --- router.ts | 10 +++++++--- router_test.ts | 10 +++++----- serveio.ts | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/router.ts b/router.ts index 7f0528a..9833d18 100644 --- a/router.ts +++ b/router.ts @@ -1,8 +1,12 @@ // Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license. -import {IncomingHttpRequest, serve, ServeOptions} from "./server.ts"; -import {encode} from "https://deno.land/std@v0.3.1/strings/strings.ts"; +import { + serve, + ServeOptions, + ServerRequest +} from "./server.ts"; +import { encode } from "https://deno.land/std@v0.3.1/strings/strings.ts"; -export type RoutedServerRequest = IncomingHttpRequest & { +export type RoutedServerRequest = ServerRequest & { match?: RegExpMatchArray; }; diff --git a/router_test.ts b/router_test.ts index 2d75773..25b0aa3 100644 --- a/router_test.ts +++ b/router_test.ts @@ -52,8 +52,8 @@ test(function httpMatchNearest() { }); test(async function router() { const server = createRouter(); - server.handle("/index", async (req, { respond }) => { - await respond({ + server.handle("/index", async req => { + await req.respond({ status: 200, headers: new Headers({ "content-type": "text/plain" @@ -61,9 +61,9 @@ test(async function router() { body: new StringReader("ok") }); }); - server.handle(new RegExp("/foo/(?.+)"), async (req, { respond }) => { + server.handle(new RegExp("/foo/(?.+)"), async req => { const { id } = req.match.groups; - await respond({ + await req.respond({ status: 200, headers: new Headers({ "content-type": "application/json" @@ -71,7 +71,7 @@ test(async function router() { body: new StringReader(JSON.stringify({ id })) }); }); - server.handle("/no-response", async (req, res) => {}); + server.handle("/no-response", async req => {}); const cancel = defer(); try { server.listen("127.0.0.1:8898", { cancel: cancel.promise }); diff --git a/serveio.ts b/serveio.ts index eb190ae..1805e30 100644 --- a/serveio.ts +++ b/serveio.ts @@ -18,7 +18,8 @@ import { encode } from "https://deno.land/std@v0.3.1/strings/strings.ts"; import { - ClientRequest, IncomingHttpRequest, + ClientRequest, + IncomingHttpRequest, IncomingHttpResponse, ServerRequest, ServerResponse