Added GITHUB_API env var

This commit is contained in:
Kalle Fagerberg 2022-08-12 17:08:09 +02:00
parent 0d1525995c
commit cb9b077fca
No known key found for this signature in database
GPG key ID: C0DD6EBC34092609
3 changed files with 8 additions and 3 deletions

View file

@ -5,7 +5,8 @@ import { COLORS, Theme } from "./src/theme.ts";
import { Error400, Error404 } from "./src/error_page.ts"; import { Error400, Error404 } 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 apiEndpoint = Deno.env.get("GITHUB_API") || CONSTANTS.DEFAULT_GITHUB_API;
const client = new GithubAPIClient(apiEndpoint);
export default async (req: Request) => { export default async (req: Request) => {
const params = parseParams(req); const params = parseParams(req);

View file

@ -1,5 +1,6 @@
import { soxa } from "../deps.ts"; import { soxa } from "../deps.ts";
import { UserInfo } from "./user_info.ts"; import { UserInfo } from "./user_info.ts";
import { CONSTANTS } from "./utils.ts";
import type { import type {
GitHubUserActivity, GitHubUserActivity,
GitHubUserIssue, GitHubUserIssue,
@ -8,7 +9,9 @@ import type {
} from "./user_info.ts"; } from "./user_info.ts";
export class GithubAPIClient { export class GithubAPIClient {
constructor() { constructor(
private apiEndpoint: string = CONSTANTS.DEFAULT_GITHUB_API,
) {
} }
async requestUserInfo( async requestUserInfo(
token: string | undefined, token: string | undefined,
@ -114,7 +117,7 @@ export class GithubAPIClient {
) { ) {
const variables = { username: username }; const variables = { username: username };
const response = await soxa.post( const response = await soxa.post(
"https://api.github.com/graphql", this.apiEndpoint,
{}, {},
{ {
data: { query: query, variables }, data: { query: query, variables },

View file

@ -62,6 +62,7 @@ export const CONSTANTS = {
DEFAULT_MARGIN_H: 0, DEFAULT_MARGIN_H: 0,
DEFAULT_NO_BACKGROUND: false, DEFAULT_NO_BACKGROUND: false,
DEFAULT_NO_FRAME: false, DEFAULT_NO_FRAME: false,
DEFAULT_GITHUB_API: "https://api.github.com/graphql",
}; };
export enum RANK { export enum RANK {