Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions client/app.ts → client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { createReadStream } from 'node:fs';

import * as dotenv from 'dotenv';
import Koa from 'koa';
import serve from 'koa-static';

dotenv.config();

const app = new Koa();
const port = 3000;
const port = 8080;
const redirect = 'docs';
const subdir = 'public';

Expand All @@ -33,6 +30,6 @@ app
context.body = createReadStream(`${redirect}/404.html`);
}
})
.listen(port, () => console.log(`Koa is listening port: ${port}`));
.listen(port, () => console.log(`Client port: ${port}`));

export default app;
24 changes: 14 additions & 10 deletions client/routes/requests/languages.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import axios from 'axios';

import router from '../../../local';

const localToken = process.env.GH_PAT;
const { protocol, hostname } = window.location;
const isLocal = hostname !== 'gitlang';
console.log('hostname:', hostname);

const localApi = async (owner: string, repos: string[]) => {
try {
const allLanguages = JSON.parse(
await router.langs(owner, repos, localToken),
const allLanguages: { data: { [key: string]: number }[] } = await axios.get(
`${protocol}//${hostname}:3000/gitlang/github/langs`,
{
params: {
owner,
repos: JSON.stringify(repos),
},
},
);

if (allLanguages && allLanguages.length > 0) {
return allLanguages;
}
if (allLanguages && allLanguages.data && allLanguages.data.length > 0)
return allLanguages.data;
return [];
} catch (error) {
console.error('Error getting token from auth api', error);
Expand Down Expand Up @@ -40,6 +44,6 @@ const serverApi = async (owner: string, repos: string[]) => {
}
};

const languages = localToken ? localApi : serverApi;
const languages = isLocal ? localApi : serverApi;

export default languages;
19 changes: 12 additions & 7 deletions client/routes/requests/repositories.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import axios from 'axios';

import router from '../../../local';

const localToken = process.env.GH_PAT;
const { protocol, hostname } = window.location;
const isLocal = hostname !== 'gitlang';
console.log('hostname:', hostname);

const localApi = async (username: string) => {
try {
const allRepos = JSON.parse(await router.repos(username, localToken));
if (allRepos && allRepos.length > 0) {
return allRepos;
const allRepos: { data: [] } = await axios.get(
`${protocol}//${hostname}:3000/gitlang/github/repos`,
{
params: { username },
},
);
if (allRepos && allRepos.data && allRepos.data.length > 0) {
return allRepos.data;
}
return [];
} catch (error) {
Expand All @@ -35,6 +40,6 @@ const serverApi = async (username: string) => {
}
};

const repositories = localToken ? localApi : serverApi;
const repositories = isLocal ? localApi : serverApi;

export default repositories;
4 changes: 2 additions & 2 deletions gitlangRoutes/helpers/github/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from '@octokit/rest';

let octokit: Octokit;

const fetchLanguage = async (owner: string, repo: string, token?: string) => {
const fetchLanguage = async (owner: string, repo: string, token: string) => {
try {
if (!octokit) {
if (!token) {
Expand All @@ -20,7 +20,7 @@ const fetchLanguage = async (owner: string, repo: string, token?: string) => {
}
};

const languages = async (owner: string, names: string[], token?: string) => {
const languages = async (owner: string, names: string[], token: string) => {
const langs = [];
for (const repo of names) {
langs.push(await fetchLanguage(owner, repo, token));
Expand Down
2 changes: 1 addition & 1 deletion gitlangRoutes/helpers/github/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from '@octokit/rest';

let octokit: Octokit;

const repositories = async (username: string, token?: string) => {
const repositories = async (username: string, token: string) => {
try {
if (!octokit) {
if (!token) {
Expand Down
30 changes: 0 additions & 30 deletions gitlangRoutes/requests/gitlangLocal.ts

This file was deleted.

6 changes: 4 additions & 2 deletions gitlangRoutes/requests/gitlangRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import auth from '../helpers/github/auth';
import languages from '../helpers/github/languages';
import repositories from '../helpers/github/repositories';

const environmentToken = process.env.GH_PAT;

const router = new Router({ prefix: '/github' });

router.get(
Expand All @@ -13,7 +15,7 @@ router.get(
response: { status: number; body: string };
}) => {
try {
const token = await auth();
const token = environmentToken || (await auth());
const { owner } = context.request.query;
const { repos } = context.request.query;
const repoList = JSON.parse(repos) as string[];
Expand All @@ -39,7 +41,7 @@ router.get(
response: { status: number; body: string };
}) => {
try {
const token = await auth();
const token = environmentToken || (await auth());
const { username } = context.request.query;
const response = await repositories(username, token);
if (response && response.length > 0) {
Expand Down
5 changes: 0 additions & 5 deletions local.ts

This file was deleted.

Loading