Skip to content

Commit

Permalink
fix: use requestPath for /json
Browse files Browse the repository at this point in the history
Fixes elysiajs#161.

This will also work when you don't specify any prefix to Elysia but uses Traefik Middlewares to strip /api prefix too.
  • Loading branch information
Hazmi35 committed Nov 29, 2024
1 parent 062995e commit 95168c0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -64,9 +65,9 @@ export const swagger = async <Path extends string = '/swagger'>(

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
}
Expand All @@ -83,7 +84,7 @@ export const swagger = async <Path extends string = '/swagger'>(
const scalarConfiguration: ReferenceConfiguration = {
spec: {
...scalarConfig.spec,
url: `/${relativePath}/json`
url: resolve(reqPath, '/json')
},
...scalarConfig,
// so we can showcase the elysia theme
Expand Down

0 comments on commit 95168c0

Please sign in to comment.