Add parseParams to utils

This commit is contained in:
ryo-ma 2020-08-24 21:31:03 +09:00
parent 869c528101
commit 6a64dbe1f1
2 changed files with 11 additions and 1 deletions

View file

@ -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);

View file

@ -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]);
}