-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.ts
More file actions
43 lines (36 loc) · 1.06 KB
/
Copy pathgithub.ts
File metadata and controls
43 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { type NextRequest } from 'next/server';
interface Repository {
fork: boolean;
stargazers_count: number;
}
interface User {
followers: number;
}
export const config = {
runtime: 'experimental-edge'
};
export default async function handler(req: NextRequest) {
const userResponse = await fetch('https://api.github.com/users/codewithdev');
const userReposResponse = await fetch(
'https://api.github.com/users/codewithdev/repos?per_page=100'
);
const user = await userResponse.json() as User;
const repositories = await userReposResponse.json() as Repository[];
const mine = repositories.filter((repo: Repository) => !repo.fork);
const stars = mine.reduce((accumulator: number, repository: Repository) => {
return accumulator + repository.stargazers_count;
}, 0);
return new Response(
JSON.stringify({
followers: user.followers,
stars
}),
{
status: 200,
headers: {
'content-type': 'application/json',
'cache-control': 'public, s-maxage=1200, stale-while-revalidate=600'
}
}
);
}