Skip to content

Commit

Permalink
add schedule route
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Feb 2, 2024
1 parent e712704 commit 68f6685
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Elysia, NotFoundError } from 'elysia'
import { parseHTML } from 'linkedom'
import ExpiryMap from 'expiry-map'

const validPaths = ['stats', 'rankings', 'standings', 'history', 'scoreboard']
const validPaths = ['stats', 'rankings', 'standings', 'history', 'scoreboard', 'schedule']

// set cache expiry to 30 min
const cache = new ExpiryMap(30 * 60 * 1000)
Expand Down Expand Up @@ -51,6 +51,25 @@ export const app = new Elysia()
// set cache key
store.cacheKey = path + (page ?? '')
})
// schedule route to retrieve game dates
.get('/schedule/:sport/:division/*', async ({ store, params }) => {
if (cache.has(store.cacheKey)) {
return cache.get(store.cacheKey)
}
const { sport, division } = params

const req = await fetch(
`https://data.ncaa.com/casablanca/schedule/${sport}/${division}/${params['*']}/schedule-all-conf.json`
)

if (!req.ok) {
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
}

const data = await req.json()
cache.set(store.cacheKey, data)
return data
})
// scoreboard route to fetch data from data.ncaa.com json endpoint
.get('/scoreboard/:sport/*', async ({ store, params }) => {
if (scoreboardCache.has(store.cacheKey)) {
Expand Down

0 comments on commit 68f6685

Please sign in to comment.