Skip to content

Commit 3ab0505

Browse files
committed
fix: fetch contributors from server
1 parent 32b1efb commit 3ab0505

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ export class Api {
250250
return contributors;
251251
}
252252

253+
async fetchAllContributorsFromClient(): Promise<Contributor[]> {
254+
const res = await fetch('api/contributors');
255+
return (await res.json()).contributors;
256+
}
257+
253258
async fetchNpmInfo(npmId: string): Promise<NpmInfo | null> {
254259
try {
255260
const npmApiUrl = 'https://registry.npmjs.org/';

src/components/ExpandableContributorList/LazyExpandableContributorsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const getComponent = async () => {
2020
};
2121

2222
const getComponentProps = async () => {
23-
const contributors = await Api.instance.fetchAllContributorsWithCache();
23+
const contributors = await Api.instance.fetchAllContributorsFromClient();
2424

2525
return {contributors};
2626
};

src/pages/api/contributors.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {NextApiRequest, NextApiResponse} from 'next';
2+
import {Api} from 'src/api';
3+
4+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
5+
if (req.method !== 'GET') {
6+
res.setHeader('Allow', ['GET']);
7+
res.status(405).end(`Method ${req.method} Not Allowed`);
8+
return;
9+
}
10+
11+
const contributors = await Api.instance.fetchAllContributorsWithCache();
12+
13+
res.status(200).json({contributors});
14+
}

0 commit comments

Comments
 (0)