From a9ae1d92b7db76fe6d5bbf95629f1be3c46f543b Mon Sep 17 00:00:00 2001 From: wont-stream Date: Mon, 13 Jan 2025 13:38:24 -0500 Subject: [PATCH] Add authorization header support for API requests --- index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index ebd13e7..d28106f 100644 --- a/index.ts +++ b/index.ts @@ -6,9 +6,17 @@ type repo = { } type repos = repo[] +const fetchOpts: RequestInit = {} + +if (process.env.AuthorizationHeaderToken) { + fetchOpts.headers = { + "Authorization": `Bearer ${process.env.AuthorizationHeaderToken}` + } +} + const getTopLangs = async (type: "users" | "orgs", name: string) => { const obj: Record = {} - const userRepoResp = await fetch(`https://git.creations.works/api/v1/${type}/${name}/repos?limit=0`); + const userRepoResp = await fetch(`https://git.creations.works/api/v1/${type}/${name}/repos?limit=0`, fetchOpts); const userRepos = await userRepoResp.json() as repos; for (const repo of userRepos) {