Skip to content

Commit

Permalink
Merge pull request #1156 from hackclub/add-low-rate-limit-mode
Browse files Browse the repository at this point in the history
Add low rate limit mode
  • Loading branch information
maxwofford authored Feb 1, 2025
2 parents 308ad26 + c3fde29 commit 05a4092
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/app/api/battles/matchups/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { NextRequest } from 'next/server'
export const dynamic = 'force-dynamic'

export async function GET(request: NextRequest) {
if (process.env.NEXT_PUBLIC_LOW_RATE_LIMIT) {
return NextResponse.json(
{ error: 'Rate limit exceeded' },
{ status: 429 },
)
}
const isTutorial = request.nextUrl.searchParams.get('tutorial')

const session = await getSession()
Expand Down
4 changes: 2 additions & 2 deletions src/app/harbor/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function Harbor({
{
name: <>Wonderdome</>,
path: 'wonderdome',
component: process.env.RATE_LIMIT ? (
component: process.env.NEXT_PUBLIC_LOW_RATE_LIMIT ? (
<Battles session={session} />
) : (
<RateLimit name="The wonderdome" />
Expand All @@ -230,7 +230,7 @@ export default function Harbor({
{
name: <>Tavern 🍻</>,
path: 'tavern',
component: process.env.RATE_LIMIT ? (
component: process.env.NEXT_PUBLIC_LOW_RATE_LIMIT ? (
<Tavern />
) : (
<RateLimit name="The tavern" />
Expand Down
24 changes: 0 additions & 24 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,6 @@ async function loadPersonCookies(request: NextRequest, response: NextResponse) {
}
}

// async function loadShopItemsCookie(
// request: NextRequest,
// response: NextResponse,
// ) {
// try {
// if (!request.cookies.get('shop')) {
// const shopItems = await fetchShopItems()
// console.log(shopItems.map((a) => [a.name, a.priceUs, a.priceGlobal]))
// response.cookies.set({
// name: 'shop',
// value: JSON.stringify(
// shopItems.map((a) => [a.name, a.priceUs, a.priceGlobal]),
// ),
// path: '/',
// sameSite: 'strict',
// expires: new Date(Date.now() + 60 * 60 * 1000), // In an hour
// })
// }
// } catch (e) {
// console.error('Middleware errored on shop items cookie step', e)
// }
// }

export async function userPageMiddleware(request: NextRequest) {
const response = NextResponse.next()
const session = await getSession()
Expand All @@ -186,7 +163,6 @@ export async function userPageMiddleware(request: NextRequest) {
loadWakaCookie(request, session, response),
loadSignpostFeedCookie(request, response),
loadPersonCookies(request, response),
// loadShopItemsCookie(request, response),
])

return response
Expand Down

0 comments on commit 05a4092

Please sign in to comment.