Skip to content

Commit d07c333

Browse files
committed
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.
1 parent ed00255 commit d07c333

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { Elysia, type InternalRoute } from 'elysia'
3+
import { resolve } from 'node:path';
34

45
import { SwaggerUIRender } from './swagger'
56
import { ScalarRender } from './scalar'
@@ -64,9 +65,9 @@ export const swagger = async <Path extends string = '/swagger'>(
6465

6566
const app = new Elysia({ name: '@elysiajs/swagger' })
6667

67-
app.get(path, function documentation() {
68+
app.get(path, function documentation({ path: reqPath }) {
6869
const combinedSwaggerOptions = {
69-
url: `/${relativePath}/json`,
70+
url: resolve(reqPath, '/json'),
7071
dom_id: '#swagger-ui',
7172
...swaggerOptions
7273
}
@@ -83,7 +84,7 @@ export const swagger = async <Path extends string = '/swagger'>(
8384
const scalarConfiguration: ReferenceConfiguration = {
8485
spec: {
8586
...scalarConfig.spec,
86-
url: `/${relativePath}/json`
87+
url: resolve(reqPath, '/json')
8788
},
8889
...scalarConfig,
8990
// so we can showcase the elysia theme

0 commit comments

Comments
 (0)