Skip to content

Commit

Permalink
Merge pull request #8 from keroxp/v0.7.1
Browse files Browse the repository at this point in the history
fix: use listenAndServe for router
  • Loading branch information
keroxp authored Apr 25, 2019
2 parents d67c26a + 852395a commit b6ea50f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { serve, ServeOptions, ServerRequest } from "./server.ts";
import { listenAndServe, ServeOptions, ServerRequest } from "./server.ts";
import { encode } from "https://deno.land/[email protected]/strings/strings.ts";

export type RoutedServerRequest = ServerRequest & {
Expand Down Expand Up @@ -53,9 +53,9 @@ export function createRouter(): HttpRouter {
routes.push({ pattern, handlers });
},
listen(addr: string, opts?: ServeOptions) {
const server = serve(addr, opts);
(async () => {
for await (const req of server) {
listenAndServe(
addr,
async req => {
let { pathname } = new URL(req.url, addr);
const { index, match } = findLongestAndNearestMatch(
pathname,
Expand Down Expand Up @@ -83,8 +83,9 @@ export function createRouter(): HttpRouter {
body: encode("Not Found")
});
}
}
})();
},
opts
);
}
};
}

0 comments on commit b6ea50f

Please sign in to comment.