8000 Switch to hono's build in bearerAuth · lassejlv/postgres_http@3070c0a · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Switch to hono's build in bearerAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejlv committed Dec 9, 2024
1 parent 44c3d31 commit 3070c0a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import { Pool } from 'pg'
import { z } from 'zod'
import { authMiddleware } from './middleware/auth'
import { logger } from 'hono/logger'
import { bearerAuth } from 'hono/bearer-auth'

const pool = new Pool({
connectionString: process.env.DATABASE_URL,
// connection timeout = 1 minute
connectionTimeoutMillis: 60 * 1000,
})

const app = new Hono()

const token = process.env.API_TOKEN;
if (!token) throw new Error('API_TOKEN is required')

app.use(logger())
app.use("*", authMiddleware)

app.use("*", bearerAuth({ token }))

const schema = z.object({
query: z.string(),
Expand Down

0 comments on commit 3070c0a

Please sign in to comment.
0