From 869c5281012f86716582ee572fd444a570910a64 Mon Sep 17 00:00:00 2001 From: ryo-ma Date: Mon, 24 Aug 2020 21:08:21 +0900 Subject: [PATCH] Modify dev_main.ts as common --- dev_main.ts | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/dev_main.ts b/dev_main.ts index 2574661..cf1ef32 100644 --- a/dev_main.ts +++ b/dev_main.ts @@ -1,34 +1,7 @@ import { serve } from "https://deno.land/std@0.66.0/http/server.ts"; -import { GithubAPIClient } from "./src/github_api_client.ts"; -import { Card } from "./src/card.ts"; -import "https://deno.land/x/dotenv@v0.5.0/load.ts"; +import requestHandler from "./index.ts"; const s = serve({ port: 8080 }); -const client = new GithubAPIClient(); -const cacheMaxAge = 7200; for await (const req of s) { - const username = new URLSearchParams(req.url.split("?")[1]).get("username"); - - if (username != null) { - const userInfo = await client.requestUserInfo(username); - req.respond( - { - body: new Card().render(userInfo), - headers: new Headers( - { - "Content-Type": "image/svg+xml", - "Cache-Control": `public, max-age: ${cacheMaxAge}`, - }, - ), - }, - ); - } else { - req.respond( - { - body: "Can not find a query parameter: username", - status: 404, - headers: new Headers({ "Content-Type": "text" }), - }, - ); - } + requestHandler(req); }