Skip to content

Commit

Permalink
fix reading request headers for elysia 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Dec 5, 2024
1 parent afcc25a commit 91bf598
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ export const app = new Elysia()
// create a store to hold cache key
.state('cacheKey', '')
// validate request / set cache key
.onBeforeHandle({ as: 'global' }, ({ store, set, headers, path, query: { page } }) => {
.onBeforeHandle({ as: 'global' }, ({ store, set, request, path, query: { page } }) => {
set.headers['Content-Type'] = 'application/json'

// validate custom header value
if (process.env.NCAA_HEADER_KEY && headers['x-ncaa-key'] !== process.env.NCAA_HEADER_KEY) {
if (
process.env.NCAA_HEADER_KEY &&
request.headers.get('x-ncaa-key') !== process.env.NCAA_HEADER_KEY
) {
set.status = 401
throw new Error('Unauthorized')
}
Expand Down

0 comments on commit 91bf598

Please sign in to comment.