diff --git a/routes/github/commits.ts b/routes/github/commits.ts index 125ca04f..8099421e 100644 --- a/routes/github/commits.ts +++ b/routes/github/commits.ts @@ -2,9 +2,13 @@ import { Request, Response } from "express"; import { seconds } from "../../utils/misc.js"; import { getCommits } from "./lib/commits.js"; -export default async function route(req: Request, res: Response) { +type Params = { org: string; repo: string }; +type Query = { from: string; to?: string; path?: string }; +type IRequest = Request; + +export default async function route(req: IRequest, res: Response) { const { org, repo } = req.params; - const { from, to , path } = req.query; + const { from, to, path } = req.query; if (!from || typeof from !== "string") { res.set("Content-Type", "text/plain"); return res.status(400).send("query parameter 'from' is required"); @@ -32,6 +36,7 @@ export default async function route(req: Request, res: Response) { } res.json(commits); } catch (error) { + res.set("Content-Type", "text/plain"); res.status(404).send(error.message); } } diff --git a/routes/github/contributors.ts b/routes/github/contributors.ts index eadcc423..aa53e8c7 100644 --- a/routes/github/contributors.ts +++ b/routes/github/contributors.ts @@ -12,7 +12,10 @@ const cache = new DiskCache({ path: "github/contributors", }); -export default async function route(req: Request, res: Response) { +type Params = { org: string; repo: string }; +type IRequest = Request; + +export default async function route(req: IRequest, res: Response) { const { org, repo } = req.params; const cacheKey = `${org}/${repo}`; diff --git a/routes/w3c/group.ts b/routes/w3c/group.ts index 677ae957..1665c840 100644 --- a/routes/w3c/group.ts +++ b/routes/w3c/group.ts @@ -39,7 +39,10 @@ const LEGACY_SHORTNAMES = new Map([ ["i18n", "i18n-core"], // more than 10 instances ]); -export default async function route(req: Request, res: Response) { +type Params = { shortname?: string; type?: string }; +type IRequest = Request; + +export default async function route(req: IRequest, res: Response) { const { shortname, type } = req.params; if (!shortname) { if (req.headers.accept?.includes("text/html")) { @@ -57,7 +60,7 @@ export default async function route(req: Request, res: Response) { } try { - const requestedType = type as GroupType; + const requestedType = type as GroupType | undefined; const groupInfo = await getGroupInfo(shortname, requestedType); res.set("Cache-Control", `max-age=${seconds("24h")}`); res.json(groupInfo); @@ -70,7 +73,7 @@ export default async function route(req: Request, res: Response) { async function getGroupInfo( shortname: GroupMeta["name"], - requestedType: GroupType, + requestedType?: GroupType, ) { const cacheKey = `${shortname}/${requestedType || ""}`; if (cache.expires(cacheKey) > 1000) { @@ -160,7 +163,7 @@ async function getPatentPolicy( } } -function getGroupMeta(shortname: string, requestedType: GroupType) { +function getGroupMeta(shortname: string, requestedType?: GroupType) { const types = requestedType ? [requestedType] : (Object.keys(groups) as GroupType[]); diff --git a/routes/w3c/index.ts b/routes/w3c/index.ts index 4830f686..4a809574 100644 --- a/routes/w3c/index.ts +++ b/routes/w3c/index.ts @@ -4,6 +4,6 @@ import cors from "cors"; import groupsRoute from "./group.js"; const w3c = Router(); -w3c.get("/groups/:shortname?/:type?", cors(), groupsRoute); +w3c.get("/groups{/:shortname}{/:type}", cors(), groupsRoute); export default w3c; diff --git a/routes/xref/index.ts b/routes/xref/index.ts index 50c31e23..7faf4ed9 100644 --- a/routes/xref/index.ts +++ b/routes/xref/index.ts @@ -25,7 +25,7 @@ xref .options("/search", cors({ methods: ["POST", "GET"], maxAge: ms("1day") })) .get("/search", cors(), searchRouteGet) .post("/search", express.json({ limit: "2mb" }), cors(), searchRoutePost); -xref.get("/meta/:field?", cors(), metaRoute); +xref.get("/meta{/:field}", cors(), metaRoute); xref.post("/update", authGithubWebhook(env("W3C_WEBREF_SECRET")), updateRoute); xref.use("/data", express.static(path.join(DATA_DIR, "xref"))); diff --git a/scripts/update-w3c-groups-list.ts b/scripts/update-w3c-groups-list.ts index 7ace808e..6a238568 100644 --- a/scripts/update-w3c-groups-list.ts +++ b/scripts/update-w3c-groups-list.ts @@ -75,7 +75,7 @@ export default async function update() { case "group": return g; case "tf": - return g.members; + return g.members || []; default: return []; }