|
1 | | -import { NodeHttpServer } from "@effect/platform-node" |
2 | 1 | import { Effect, Layer, Redacted, Schema } from "effect" |
3 | 2 | import { HttpApiBuilder, HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi" |
4 | | -import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http" |
5 | | -import { createServer } from "node:http" |
| 3 | +import { HttpRouter, HttpServer, HttpServerRequest } from "effect/unstable/http" |
6 | 4 | import { AppRuntime } from "@/effect/app-runtime" |
7 | 5 | import { InstanceRef, WorkspaceRef } from "@/effect/instance-ref" |
| 6 | +import { Observability } from "@/effect/observability" |
| 7 | +import { memoMap } from "@/effect/run-service" |
8 | 8 | import { Flag } from "@/flag/flag" |
9 | 9 | import { InstanceBootstrap } from "@/project/bootstrap" |
10 | 10 | import { Instance } from "@/project/instance" |
| 11 | +import { lazy } from "@/util/lazy" |
11 | 12 | import { Filesystem } from "@/util/filesystem" |
12 | | -import { Permission } from "@/permission" |
13 | | -import { ProviderAuth } from "@/provider/auth" |
14 | | -import { Question } from "@/question" |
15 | 13 | import { PermissionApi, PermissionLive } from "./permission" |
16 | 14 | import { ProviderApi, ProviderLive } from "./provider" |
17 | 15 | import { QuestionApi, QuestionLive } from "./question" |
@@ -113,26 +111,24 @@ export namespace ExperimentalHttpApiServer { |
113 | 111 | const ProviderSecured = ProviderApi.middleware(Authorization) |
114 | 112 |
|
115 | 113 | export const routes = Layer.mergeAll( |
116 | | - HttpApiBuilder.layer(QuestionSecured, { openapiPath: "/experimental/httpapi/question/doc" }).pipe( |
117 | | - Layer.provide(QuestionLive), |
118 | | - ), |
| 114 | + HttpApiBuilder.layer(QuestionSecured).pipe(Layer.provide(QuestionLive)), |
119 | 115 | HttpApiBuilder.layer(PermissionSecured, { openapiPath: "/experimental/httpapi/permission/doc" }).pipe( |
120 | 116 | Layer.provide(PermissionLive), |
121 | 117 | ), |
122 | 118 | HttpApiBuilder.layer(ProviderSecured, { openapiPath: "/experimental/httpapi/provider/doc" }).pipe( |
123 | 119 | Layer.provide(ProviderLive), |
124 | 120 | ), |
125 | | - ).pipe(Layer.provide(auth), Layer.provide(normalize), Layer.provide(instance)) |
126 | | - |
127 | | - export const layer = (opts: { hostname: string; port: number }) => |
128 | | - HttpRouter.serve(routes, { disableListenLog: true, disableLogger: true }).pipe( |
129 | | - Layer.provideMerge(NodeHttpServer.layer(createServer, { port: opts.port, host: opts.hostname })), |
130 | | - ) |
| 121 | + ).pipe( |
| 122 | + Layer.provide(auth), |
| 123 | + Layer.provide(normalize), |
| 124 | + Layer.provide(instance), |
| 125 | + Layer.provide(HttpServer.layerServices), |
| 126 | + Layer.provideMerge(Observability.layer), |
| 127 | + ) |
131 | 128 |
|
132 | | - export const layerTest = HttpRouter.serve(routes, { disableListenLog: true, disableLogger: true }).pipe( |
133 | | - Layer.provideMerge(NodeHttpServer.layerTest), |
134 | | - Layer.provideMerge(Question.defaultLayer), |
135 | | - Layer.provideMerge(Permission.defaultLayer), |
136 | | - Layer.provideMerge(ProviderAuth.defaultLayer), |
| 129 | + export const webHandler = lazy(() => |
| 130 | + HttpRouter.toWebHandler(routes, { |
| 131 | + memoMap, |
| 132 | + }), |
137 | 133 | ) |
138 | 134 | } |
0 commit comments