mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Modify dev_main.ts as common
This commit is contained in:
parent
76a68918ad
commit
869c528101
1 changed files with 2 additions and 29 deletions
31
dev_main.ts
31
dev_main.ts
|
|
@ -1,34 +1,7 @@
|
||||||
import { serve } from "https://deno.land/std@0.66.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.66.0/http/server.ts";
|
||||||
import { GithubAPIClient } from "./src/github_api_client.ts";
|
import requestHandler from "./index.ts";
|
||||||
import { Card } from "./src/card.ts";
|
|
||||||
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
|
||||||
|
|
||||||
const s = serve({ port: 8080 });
|
const s = serve({ port: 8080 });
|
||||||
const client = new GithubAPIClient();
|
|
||||||
const cacheMaxAge = 7200;
|
|
||||||
for await (const req of s) {
|
for await (const req of s) {
|
||||||
const username = new URLSearchParams(req.url.split("?")[1]).get("username");
|
requestHandler(req);
|
||||||
|
|
||||||
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" }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue