From cb9b077fca7473faa88b507f37bbf2a62a2a2ff4 Mon Sep 17 00:00:00 2001 From: Kalle Fagerberg Date: Fri, 12 Aug 2022 17:08:09 +0200 Subject: [PATCH] Added GITHUB_API env var --- index.ts | 3 ++- src/github_api_client.ts | 7 +++++-- src/utils.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index a1ab91a..9dd46fe 100644 --- a/index.ts +++ b/index.ts @@ -5,7 +5,8 @@ import { COLORS, Theme } from "./src/theme.ts"; import { Error400, Error404 } from "./src/error_page.ts"; import "https://deno.land/x/dotenv@v0.5.0/load.ts"; -const client = new GithubAPIClient(); +const apiEndpoint = Deno.env.get("GITHUB_API") || CONSTANTS.DEFAULT_GITHUB_API; +const client = new GithubAPIClient(apiEndpoint); export default async (req: Request) => { const params = parseParams(req); diff --git a/src/github_api_client.ts b/src/github_api_client.ts index 4ca5e1f..8b5daf9 100644 --- a/src/github_api_client.ts +++ b/src/github_api_client.ts @@ -1,5 +1,6 @@ import { soxa } from "../deps.ts"; import { UserInfo } from "./user_info.ts"; +import { CONSTANTS } from "./utils.ts"; import type { GitHubUserActivity, GitHubUserIssue, @@ -8,7 +9,9 @@ import type { } from "./user_info.ts"; export class GithubAPIClient { - constructor() { + constructor( + private apiEndpoint: string = CONSTANTS.DEFAULT_GITHUB_API, + ) { } async requestUserInfo( token: string | undefined, @@ -114,7 +117,7 @@ export class GithubAPIClient { ) { const variables = { username: username }; const response = await soxa.post( - "https://api.github.com/graphql", + this.apiEndpoint, {}, { data: { query: query, variables }, diff --git a/src/utils.ts b/src/utils.ts index e4067a1..9f868f7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,6 +62,7 @@ export const CONSTANTS = { DEFAULT_MARGIN_H: 0, DEFAULT_NO_BACKGROUND: false, DEFAULT_NO_FRAME: false, + DEFAULT_GITHUB_API: "https://api.github.com/graphql", }; export enum RANK {