Skip to content

Commit

Permalink
feat: adds imports and query token authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikstrasser committed Oct 25, 2024
1 parent 40b9ec3 commit fa6d99b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/runtime/server/api/reload-dcupl.get.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { createError, defineEventHandler, getHeader, getQuery, useNitroApp, useRuntimeConfig } from '#imports'

export default defineEventHandler(async (event) => {
const authorization = getHeader(event, 'Authorization')
const authorizationHeader = getHeader(event, 'Authorization')
const { token: authorizationToken } = getQuery(event)

const authorization = authorizationHeader || authorizationToken

const { dcupl } = useRuntimeConfig()

if (authorization !== dcupl.reloadHook?.secret) {
throw createError({
status: 401,
statusMessage: 'Unauthorized',
})
}
const nitroApp = useNitroApp()
if (nitroApp._dcuplSession) {
await nitroApp._dcuplSession.init()
if (nitroApp._dcuplNitroInstance) {
await nitroApp._dcuplNitroInstance.init()
console.info('[DCUPL] Reloaded nitro instance')
}
return {
Expand Down

0 comments on commit fa6d99b

Please sign in to comment.