diff --git a/apps/effect-worker-api/src/index.ts b/apps/effect-worker-api/src/index.ts index a52d23b..f49746e 100644 --- a/apps/effect-worker-api/src/index.ts +++ b/apps/effect-worker-api/src/index.ts @@ -5,7 +5,7 @@ * * @module */ -import { runtime, handleRequest, openApiSpec } from "@/runtime" +import { runtime, handleRequest } from "@/runtime" import { withCloudflareBindings } from "@/services" /** @@ -13,14 +13,6 @@ import { withCloudflareBindings } from "@/services" */ export default { async fetch(request: Request, env: Env, ctx: ExecutionContext) { - const url = new URL(request.url) - - // Serve OpenAPI spec at /api/openapi.json - if (url.pathname === "/api/openapi.json") { - return Response.json(openApiSpec) - } - - // HTTP REST API // Handle request with Cloudflare bindings available via FiberRef const effect = handleRequest(request).pipe(withCloudflareBindings(env, ctx)) diff --git a/apps/effect-worker-api/src/runtime.ts b/apps/effect-worker-api/src/runtime.ts index 2dce9ae..8f57682 100644 --- a/apps/effect-worker-api/src/runtime.ts +++ b/apps/effect-worker-api/src/runtime.ts @@ -6,7 +6,7 @@ * @module */ import { Effect, Layer, ManagedRuntime } from "effect" -import { HttpApiBuilder, HttpServer, OpenApi } from "@effect/platform" +import { HttpApiBuilder, HttpApiScalar, HttpServer } from "@effect/platform" import * as ServerRequest from "@effect/platform/HttpServerRequest" import * as ServerResponse from "@effect/platform/HttpServerResponse" import { WorkerApi } from "@repo/contracts" @@ -20,12 +20,15 @@ import { MiddlewareLive } from "@/services" * Middleware layers are provided here so their implementations are available, * but the middleware effects run per-request. */ +const ApiLive = HttpApiBuilder.api(WorkerApi).pipe(Layer.provide(HttpGroupsLive)) + const ApiLayer = Layer.mergeAll( - HttpApiBuilder.api(WorkerApi).pipe(Layer.provide(HttpGroupsLive)), + ApiLive, HttpApiBuilder.Router.Live, HttpApiBuilder.Middleware.layer, - HttpServer.layerContext -).pipe(Layer.provide(MiddlewareLive)) + HttpServer.layerContext, + HttpApiScalar.layer({ path: "/docs" }).pipe(Layer.provide(ApiLive)) +).pipe(Layer.provideMerge(MiddlewareLive)) /** * Shared runtime instance. @@ -64,10 +67,3 @@ export const handleRequest = (request: Request) => return ServerResponse.toWeb(response) }) - -/** - * OpenAPI specification for the API. - * - * Generated from the WorkerApi definition. - */ -export const openApiSpec = OpenApi.fromApi(WorkerApi)