From 95168c0679c27c18299f44e78ef2be17331c3162 Mon Sep 17 00:00:00 2001 From: Hazmi Alfarizqi Date: Fri, 18 Oct 2024 00:57:35 +0700 Subject: [PATCH] fix: use requestPath for /json Fixes #161. This will also work when you don't specify any prefix to Elysia but uses Traefik Middlewares to strip /api prefix too. --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 621270e..584d11a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import { Elysia, type InternalRoute } from 'elysia' +import { resolve } from 'node:path'; import { SwaggerUIRender } from './swagger' import { ScalarRender } from './scalar' @@ -64,9 +65,9 @@ export const swagger = async ( const app = new Elysia({ name: '@elysiajs/swagger' }) - app.get(path, function documentation() { + app.get(path, function documentation({ path: reqPath }) { const combinedSwaggerOptions = { - url: `/${relativePath}/json`, + url: resolve(reqPath, '/json'), dom_id: '#swagger-ui', ...swaggerOptions } @@ -83,7 +84,7 @@ export const swagger = async ( const scalarConfiguration: ReferenceConfiguration = { spec: { ...scalarConfig.spec, - url: `/${relativePath}/json` + url: resolve(reqPath, '/json') }, ...scalarConfig, // so we can showcase the elysia theme