refactor(server): use JSON response for OpenAPI doc route (#26447)
This commit is contained in:
@@ -155,13 +155,15 @@ const instanceRoutes = Layer.mergeAll(rawInstanceRoutes, instanceApiRoutes).pipe
|
|||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
const openApiDocument = OpenApi.fromApi(PublicApi)
|
// `OpenApi.fromApi` is non-trivial; defer until /doc is actually hit so
|
||||||
const openApiDocumentJson = JSON.stringify(openApiDocument)
|
// processes that never serve it (CLI, scripts) don't pay at module load.
|
||||||
|
// `HttpServerResponse.jsonUnsafe` runs JSON.stringify eagerly, so caching
|
||||||
|
// the response also caches the serialized body — every /doc request reuses
|
||||||
|
// the same Uint8Array instead of re-stringifying the spec.
|
||||||
|
const docResponse = lazy(() => HttpServerResponse.jsonUnsafe(OpenApi.fromApi(PublicApi)))
|
||||||
|
|
||||||
const docRoute = HttpRouter.use((router) =>
|
const docRoute = HttpRouter.use((router) =>
|
||||||
router.add("GET", "/doc", () =>
|
router.add("GET", "/doc", () => Effect.succeed(docResponse())),
|
||||||
Effect.succeed(HttpServerResponse.text(openApiDocumentJson, { headers: { "content-type": "application/json" } })),
|
|
||||||
),
|
|
||||||
).pipe(Layer.provide(authOnlyRouterLayer))
|
).pipe(Layer.provide(authOnlyRouterLayer))
|
||||||
|
|
||||||
const uiRoute = HttpRouter.use((router) =>
|
const uiRoute = HttpRouter.use((router) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user