Skip to content

Commit

Permalink
Added GITHUB_API env var
Browse files Browse the repository at this point in the history
  • Loading branch information
applejag committed Aug 12, 2022
1 parent 0d15259 commit cb9b077
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/github_api_client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { soxa } from "../deps.ts";
import { UserInfo } from "./user_info.ts";
import { CONSTANTS } from "./utils.ts";
import type {
GitHubUserActivity,
GitHubUserIssue,
Expand All @@ -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,
Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cb9b077

Please sign in to comment.