Skip to content

Commit

Permalink
feat(Queue): require password to access jobs dashboard (#319)
Browse files Browse the repository at this point in the history
* feat(Queue): add pw to access

* add example env
  • Loading branch information
mikewuu authored Nov 1, 2024
1 parent 5e7a332 commit f202916
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/pull_requests
NEXT_PUBLIC_APP_URL=
NEXT_PUBLIC_APP_LOG_LEVEL=info
QUEUE_DRIVER=redis
QUEUE_DASHBOARD_PASSWORD=password

# AWS
AWS_SECRET_KEY_ID=
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
"eslint-plugin-jest": "^28.2.0",
"express-basic-auth": "^1.2.1",
"framer-motion": "^11.1.9",
"gray-matter": "^4.0.3",
"he": "^1.2.0",
Expand Down
11 changes: 11 additions & 0 deletions queue-dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import express from 'express'
import basicAuth from 'express-basic-auth'
import { createBullBoard } from '@bull-board/api'
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter'
import { ExpressAdapter } from '@bull-board/express'
import { getQueue } from '@/queue/get-queue'
import { config } from '@/config'
import process from 'node:process'

const serverAdapter = new ExpressAdapter()
serverAdapter.setBasePath('/jobs')

// Add auth to require password for access
const auth = basicAuth({
users: { admin: process.env.QUEUE_DASHBOARD_PASSWORD ?? '' },
challenge: true, // Will show browser prompt
})

createBullBoard({
queues: Object.keys(config.queue.queues).map(
(queue) => new BullMQAdapter(getQueue(queue)),
Expand All @@ -17,6 +25,9 @@ createBullBoard({

const app = express()

// Apply auth middleware to all routes
app.use(auth)

app.use('/jobs', serverAdapter.getRouter())
app.get('/', (_req, res) => res.send('ok'))

Expand Down

0 comments on commit f202916

Please sign in to comment.