Skip to content

Commit

Permalink
feat: expose openapi spec under _hub secure routes (#35)
Browse files Browse the repository at this point in the history
* feat: expose openapi spec under `_hub` secure routes

* fix: apply review
  • Loading branch information
farnabaz authored Apr 2, 2024
1 parent 2e09c38 commit 45db380
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default defineNuxtModule<ModuleOptions>({
userToken: process.env.NUXT_HUB_USER_TOKEN || '',
remote: remoteArg || process.env.NUXT_HUB_REMOTE,
version,
env: process.env.NUXT_HUB_ENV || 'production'
env: process.env.NUXT_HUB_ENV || 'production',
openapi: nuxt.options.nitro.experimental?.openAPI === true
})
// validate remote option
if (hub.remote && !['true', 'production', 'preview'].includes(String(hub.remote))) {
Expand Down
26 changes: 26 additions & 0 deletions src/module/runtime/server/api/_hub/openapi.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useRuntimeConfig } from '#imports'

export default eventHandler(async (event) => {
const hub = useRuntimeConfig().hub

if (!hub.openapi) {
throw createError({
statusCode: 422,
message: 'OpenAPI not configured'
})
}

const openapi = await import('#internal/nitro/routes/openapi')
.then((mod) => mod.default)
.catch(() => undefined)

if (typeof openapi !== 'function') {
throw createError({
statusCode: 404,
message: 'not found'
})
}

return openapi(event)
})

0 comments on commit 45db380

Please sign in to comment.