| 1 | import * as FileSystem from "effect/FileSystem"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import * as Path from "effect/Path"; |
| 4 | import * as Etag from "effect/http/Etag"; |
| 5 | import * as HttpPlatform from "effect/http/HttpPlatform"; |
| 6 | import * as HttpRouter from "effect/http/HttpRouter"; |
| 7 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 8 | import { BackendClient } from "./BackendClient"; |
| 9 | import { FrontendApi } from "./NextApi"; |
| 10 | import { FrontendHandlers } from "./NextHandlers"; |
| 11 | |
| 12 | const platformLayer = Layer.mergeAll( |
| 13 | Etag.layer, |
| 14 | HttpPlatform.layer.pipe(Layer.provide(FileSystem.layerNoop({}))), |
| 15 | FileSystem.layerNoop({}), |
| 16 | Path.layer, |
| 17 | ); |
| 18 | |
| 19 | const FrontendLive = HttpApiBuilder.layer(FrontendApi).pipe( |
| 20 | Layer.provide(FrontendHandlers.pipe(Layer.provide(BackendClient.Default))), |
| 21 | Layer.provide(platformLayer), |
| 22 | ); |
| 23 | |
| 24 | const httpHandler = HttpRouter.toWebHandler(FrontendLive, { |
| 25 | disableLogger: true, |
| 26 | }); |
| 27 | |
| 28 | export const handleApiRequest = (request: Request) => |
| 29 | httpHandler.handler(request); |