Skip to content

Commit 7aa1c84

Browse files
🐛 Use Github Token to increase requests
1 parent cd317fe commit 7aa1c84

File tree

5 files changed

+98
-21
lines changed

5 files changed

+98
-21
lines changed

env.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createEnv } from '@t3-oss/env-nextjs';
2+
import { z } from 'zod';
3+
4+
export const env = createEnv({
5+
server: {
6+
GITHUB_TOKEN: z.string().optional()
7+
},
8+
client: {},
9+
// If you're using Next.js < 13.4.4, you'll need to specify the runtimeEnv manually
10+
runtimeEnv: {
11+
GITHUB_TOKEN: process.env.GITHUB_TOKEN
12+
}
13+
// For Next.js >= 13.4.4, you only need to destructure client variables:
14+
// experimental__runtimeEnv: {
15+
// NEXT_PUBLIC_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_PUBLISHABLE_KEY,
16+
// }
17+
});
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
await import('./env.mjs');
2+
13
/** @type {import('next').NextConfig} */
2-
module.exports = {
4+
const config = {
35
reactStrictMode: true,
46
images: {
5-
domains: ['avatars.githubusercontent.com', 'raw.githubusercontent.com'],
7+
domains: ['avatars.githubusercontent.com', 'raw.githubusercontent.com']
68
},
79
async redirects() {
810
return [
911
{
1012
source: '/github',
11-
destination: 'https://github.com/max-programming/hacktoberfest-projects',
12-
permanent: true,
13-
},
14-
]
15-
},
13+
destination:
14+
'https://github.com/max-programming/hacktoberfest-projects',
15+
permanent: true
16+
}
17+
];
18+
}
1619
};
20+
21+
export default config;

package-lock.json

Lines changed: 58 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@fortawesome/free-regular-svg-icons": "^6.4.2",
1616
"@fortawesome/free-solid-svg-icons": "^6.4.2",
1717
"@fortawesome/react-fontawesome": "^0.2.0",
18+
"@t3-oss/env-nextjs": "^0.6.1",
1819
"@twuni/emojify": "^1.0.2",
1920
"daisyui": "^3.7.7",
2021
"framer-motion": "^10.16.4",
@@ -24,7 +25,8 @@
2425
"react": "18.2.0",
2526
"react-dom": "18.2.0",
2627
"react-hook-form": "^7.46.2",
27-
"react-icons": "^4.11.0"
28+
"react-icons": "^4.11.0",
29+
"zod": "^3.22.2"
2830
},
2931
"devDependencies": {
3032
"@types/node": "^20.6.3",

pages/repos/[language].tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Sort from 'components/Sort';
1313
import StarsFilter from 'components/StarsFilter';
1414
import capFirstLetter from 'utils/capFirstLetter';
1515
import { RepoItem, RepoData } from 'types';
16+
import { env } from 'env.mjs';
1617

1718
interface Props {
1819
page: number;
@@ -39,9 +40,13 @@ export const getServerSideProps: GetServerSideProps<Props> = async ctx => {
3940

4041
const apiUrl = `https://api.github.com/search/repositories?q=topic%3Ahacktoberfest+language%3A${languageName}+${searchQuery}+${starsQuery}&page=${page}&per_page=21&sort=${sort}&order=${order}`;
4142

42-
const res = await fetch(apiUrl, {
43-
headers: { Accept: 'application/vnd.github.mercy-preview+json' }
44-
});
43+
const headers: HeadersInit = {
44+
Accept: 'application/vnd.github.mercy-preview+json'
45+
};
46+
47+
if (env.GITHUB_TOKEN) headers.Authorization = `Bearer ${env.GITHUB_TOKEN}`;
48+
49+
const res = await fetch(apiUrl, { headers });
4550

4651
if (!res.ok) {
4752
return {

0 commit comments

Comments
 (0)