Skip to content

Commit

Permalink
add bsync health check
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Jan 19, 2024
1 parent 48298d5 commit 8932a44
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/bsync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class BsyncService {
})
const server = http.createServer((req, res) => {
loggerMiddleware(req, res)
if (isHealth(req.url)) {
res.statusCode = 200
res.setHeader('content-type', 'application/json')
return res.end(JSON.stringify({ version: cfg.service.version }))
}
handler(req, res)
})
return new BsyncService({ ctx, server, ac })
Expand Down Expand Up @@ -89,3 +94,9 @@ export class BsyncService {
}

export default BsyncService

const isHealth = (urlStr: string | undefined) => {
if (!urlStr) return false
const url = new URL(urlStr, 'http://host')
return url.pathname === '/_health'
}

0 comments on commit 8932a44

Please sign in to comment.