diff --git a/next.config.js b/next.config.js index 4955430..5b37538 100644 --- a/next.config.js +++ b/next.config.js @@ -68,10 +68,7 @@ const nextConfig = { const nextConfigByEnv = { production: withSentryConfig(nextConfig, { - silent: true, - // https://github.com/getsentry/sentry-javascript/issues/5667 - disableServerWebpackPlugin: true, - disableClientWebpackPlugin: false + silent: true }), test: nextConfig, development: nextConfig diff --git a/pages/api/github.ts b/pages/api/github.ts index 2bcde2d..9eab9ec 100644 --- a/pages/api/github.ts +++ b/pages/api/github.ts @@ -1,5 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + const GH_HEADERS = new Headers({ - Authorization: `Bauer ${process.env.GITHUB_TOKEN}`, + Authorization: `Bauer ${process.env.GITHUB_TOKEN}` }); const starReducer = (acc: number, repo: { stargazers_count: number }) => { @@ -8,47 +10,34 @@ const starReducer = (acc: number, repo: { stargazers_count: number }) => { return result; }; -export default async function handler() { +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { try { const [userResponse, repositoriesResponse] = await Promise.all([ fetch('https://api.github.com/users/shramkoweb', { - headers: GH_HEADERS, + headers: GH_HEADERS }), fetch('https://api.github.com/users/shramkoweb/repos?per_page=100', { - headers: GH_HEADERS, - }), + headers: GH_HEADERS + }) ]); const [user, repos] = await Promise.all([ userResponse.json(), - repositoriesResponse.json(), + repositoriesResponse.json() ]); const mineRepos = repos.filter((repo: { fork: boolean }) => !repo.fork); const stars = mineRepos.reduce(starReducer, 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', - }, - }, - ); - } catch (e) { - return new Response(JSON.stringify(e), { - status: 500, - headers: { - 'content-type': 'application/json', - }, + // With edge error we have error + // https://github.com/getsentry/sentry-javascript/issues/5667 + return res.status(200).json({ + stars, + followers: user.followers }); + } catch ({ message }) { + return res.status(500).json({ message }); } } - -export const config = { - runtime: 'experimental-edge', -};