Skip to content

Commit

Permalink
feat: add unauthenticated info endpoint (#52)
Browse files Browse the repository at this point in the history
* feat: add GET config endpoint

* feat: add unauthenticated info endpoint

* Revert "feat: add unauthenticated info endpoint"

This reverts commit 0fa3a0d.

* feat: redid the authentication where some endpoints don't need authentication

* refactor: remove custom logic with authorization applied to router
  • Loading branch information
vojtechsimetka authored Apr 11, 2022
1 parent fabae4a commit 766ad50
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ export function runServer() {
context.set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS')
await next()
})
app.use(async (context, next) => {
app.use(koaBodyparser())
const router = new Router()

// Open endpoints without any authentication
router.get('/info', context => {
context.body = { name: 'bee-desktop' }
})

router.use(async (context, next) => {
const { authorization } = context.headers

if (authorization !== getApiKey()) {
Expand All @@ -33,8 +41,8 @@ export function runServer() {
}
await next()
})
app.use(koaBodyparser())
const router = new Router()

// Authenticated endpoints
router.get('/status', context => {
context.body = getStatus()
})
Expand All @@ -51,6 +59,9 @@ export function runServer() {
writeConfigYaml(context.request.body)
context.body = readConfigYaml()
})
router.get('/config', context => {
context.body = readConfigYaml()
})
router.post('/restart', async context => {
BeeManager.stop()
await BeeManager.waitForSigtermToFinish()
Expand Down

0 comments on commit 766ad50

Please sign in to comment.