mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support cache-control
This commit is contained in:
parent
7c88457692
commit
6cb75d54f3
2 changed files with 16 additions and 4 deletions
11
dev_main.ts
11
dev_main.ts
|
|
@ -5,15 +5,21 @@ import "https://deno.land/x/dotenv@v0.5.0/load.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")
|
||||
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" }),
|
||||
headers: new Headers(
|
||||
{
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Cache-Control": `public, max-age: ${cacheMaxAge}`,
|
||||
},
|
||||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
|
@ -24,6 +30,5 @@ for await (const req of s) {
|
|||
headers: new Headers({ "Content-Type": "text" }),
|
||||
},
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
index.ts
9
index.ts
|
|
@ -2,7 +2,9 @@ import { ServerRequest } from "./deps.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";
|
||||
|
||||
const client = new GithubAPIClient();
|
||||
const cacheMaxAge = 7200;
|
||||
|
||||
export default async (req: ServerRequest) => {
|
||||
const username = new URLSearchParams(req.url.split("?")[1]).get("username");
|
||||
|
|
@ -12,7 +14,12 @@ export default async (req: ServerRequest) => {
|
|||
req.respond(
|
||||
{
|
||||
body: new Card().render(userInfo),
|
||||
headers: new Headers({ "Content-Type": "image/svg+xml" }),
|
||||
headers: new Headers(
|
||||
{
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Cache-Control": `public, max-age: ${cacheMaxAge}`,
|
||||
},
|
||||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue