Update vercel-deno version to 1.1.1

This commit is contained in:
ryo-ma 2022-02-11 01:51:10 +09:00
parent ac3f80b5cb
commit 1ea1949d86
5 changed files with 27 additions and 34 deletions

View file

@ -1,7 +1,4 @@
import { serve } from "https://deno.land/std@0.66.0/http/server.ts"; import { serve } from "https://deno.land/std@0.125.0/http/server.ts";
import requestHandler from "./index.ts"; import requestHandler from "./index.ts";
const s = serve({ port: 8080 }); serve(requestHandler, { port: 8080 });
for await (const req of s) {
requestHandler(req);
}

View file

@ -1,2 +1 @@
export { ServerRequest } from "https://deno.land/std@0.66.0/http/server.ts";
export { soxa } from "https://deno.land/x/soxa@1.4/mod.ts"; export { soxa } from "https://deno.land/x/soxa@1.4/mod.ts";

View file

@ -1,14 +1,13 @@
import { ServerRequest } from "./deps.ts";
import { GithubAPIClient } from "./src/github_api_client.ts"; import { GithubAPIClient } from "./src/github_api_client.ts";
import { Card } from "./src/card.ts"; import { Card } from "./src/card.ts";
import { CONSTANTS, parseParams } from "./src/utils.ts"; import { CONSTANTS, parseParams } from "./src/utils.ts";
import { COLORS, Theme } from "./src/theme.ts"; import { COLORS, Theme } from "./src/theme.ts";
import { Error400 } from './src/error_page.ts'; import { Error400 } from "./src/error_page.ts";
import "https://deno.land/x/dotenv@v0.5.0/load.ts"; import "https://deno.land/x/dotenv@v0.5.0/load.ts";
const client = new GithubAPIClient(); const client = new GithubAPIClient();
export default async (req: ServerRequest) => { export default async (req: Request) => {
const params = parseParams(req); const params = parseParams(req);
const username = params.get("username"); const username = params.get("username");
const row = params.getNumberValue("row", CONSTANTS.DEFAULT_MAX_ROW); const row = params.getNumberValue("row", CONSTANTS.DEFAULT_MAX_ROW);
@ -43,34 +42,33 @@ export default async (req: ServerRequest) => {
if (username === null) { if (username === null) {
const [base] = req.url.split("?"); const [base] = req.url.split("?");
const error = new Error400(`<h2><code>username</code> is a required query parameter</h2> const error = new Error400(
`<h2><code>username</code> is a required query parameter</h2>
<p>The URL should look like <code>${base}?username=USERNAME</code>, where <p>The URL should look like <code>${base}?username=USERNAME</code>, where
<code>USERNAME</code> is <em>your GitHub username.</em>`); <code>USERNAME</code> is <em>your GitHub username.</em>`,
req.respond( );
return new Response(
error.render(),
{ {
body: error.render(),
status: error.status, status: error.status,
headers: new Headers({ "Content-Type": "text" }), headers: new Headers({ "Content-Type": "text" }),
}, },
); );
return;
} }
const token = Deno.env.get("GITHUB_TOKEN"); const token = Deno.env.get("GITHUB_TOKEN");
const userInfo = await client.requestUserInfo(token, username); const userInfo = await client.requestUserInfo(token, username);
if (userInfo === null) { if (userInfo === null) {
req.respond( return new Response(
"Can not find a user with userID: " + username,
{ {
body: "Can not find a user with userID: " + username,
status: 404, status: 404,
headers: new Headers({ "Content-Type": "text" }), headers: new Headers({ "Content-Type": "text" }),
}, },
); );
return;
} }
// Success Response // Success Response
req.respond( return new Response(
{ new Card(
body: new Card(
titles, titles,
ranks, ranks,
column, column,
@ -81,6 +79,7 @@ export default async (req: ServerRequest) => {
noBackground, noBackground,
noFrame, noFrame,
).render(userInfo, theme), ).render(userInfo, theme),
{
headers: new Headers( headers: new Headers(
{ {
"Content-Type": "image/svg+xml", "Content-Type": "image/svg+xml",

View file

@ -1,5 +1,3 @@
import { ServerRequest } from ".././deps.ts";
export class CustomURLSearchParams extends URLSearchParams { export class CustomURLSearchParams extends URLSearchParams {
constructor( constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams, init?: string[][] | Record<string, string> | string | URLSearchParams,
@ -31,13 +29,13 @@ export class CustomURLSearchParams extends URLSearchParams {
getBooleanValue(key: string, defaultValue: boolean): boolean { getBooleanValue(key: string, defaultValue: boolean): boolean {
if (super.has(key)) { if (super.has(key)) {
const param = super.get(key); const param = super.get(key);
return param !== null && param.toString() === 'true'; return param !== null && param.toString() === "true";
} }
return defaultValue; return defaultValue;
} }
} }
export function parseParams(req: ServerRequest): CustomURLSearchParams { export function parseParams(req: Request): CustomURLSearchParams {
const splittedURL = req.url.split("?"); const splittedURL = req.url.split("?");
if (splittedURL.length < 2) { if (splittedURL.length < 2) {
return new CustomURLSearchParams(); return new CustomURLSearchParams();

View file

@ -1,7 +1,7 @@
{ {
"builds":[{ "builds":[{
"src": "**/index.ts", "src": "**/index.ts",
"use": "vercel-deno@0.7.10" "use": "vercel-deno@1.1.1"
}], }],
"routes": [{ "src": "/.*", "dest": "/" }] "routes": [{ "src": "/.*", "dest": "/" }]
} }