diff --git a/index.ts b/index.ts index 31c7aa8..9244ad9 100644 --- a/index.ts +++ b/index.ts @@ -1,13 +1,14 @@ import { ServerRequest } from "./deps.ts"; import { GithubAPIClient } from "./src/github_api_client.ts"; import { Card } from "./src/card.ts"; +import { parseParams } from "./src/utils.ts"; import "https://deno.land/x/dotenv@v0.5.0/load.ts"; const client = new GithubAPIClient(); const cacheMaxAge = 7200; export default async (req: ServerRequest) => { - const username = new URLSearchParams(req.url.split("?")[1]).get("username"); + const username = parseParams(req).get("username"); if (username != null) { const userInfo = await client.requestUserInfo(username); diff --git a/src/utils.ts b/src/utils.ts index e69de29..9e09ba9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -0,0 +1,9 @@ +import { ServerRequest } from ".././deps.ts"; + +export function parseParams(req: ServerRequest): URLSearchParams { + const splitedURL = req.url.split("?") + if (splitedURL.length < 2){ + return new URLSearchParams(); + } + return new URLSearchParams(splitedURL[1]); +} \ No newline at end of file