Skip to content

Commit

Permalink
400 error if requesting scores over a year from now
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Mar 30, 2024
1 parent e31b95c commit 7bd2e16
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const app = new Elysia()
return data
})
// scoreboard route to fetch data from data.ncaa.com json endpoint
.get('/scoreboard/:sport/*', async ({ store, params }) => {
.get('/scoreboard/:sport/*', async ({ store, params, set }) => {
if (scoreboardCache.has(store.cacheKey)) {
return scoreboardCache.get(store.cacheKey)
}
Expand All @@ -88,8 +88,15 @@ export const app = new Elysia()
const urlDateMatcher = /(\d{4}\/\d{2}\/\d{2})|(\d{4}\/(\d{2}|P))/
let urlDate = params['*'].match(urlDateMatcher)?.[0]

// if not date in passed in url, fetch date from today.json
if (!urlDate) {
if (urlDate) {
// return 400 if date is more than a year in the future
// (had runaway bot requesting every day until I noticed it in 2195)
if (new Date(urlDate).getFullYear() > new Date().getFullYear() + 1) {
set.status = 400
throw new Error('Invalid date')
}
} else {
// if date not in passed in url, fetch date from today.json
urlDate = await getTodayUrl(params.sport, division)
}

Expand Down

0 comments on commit 7bd2e16

Please sign in to comment.