MCPcopy Create free account
hub / github.com/effect-app/libs / serve

Function serve

repos/effect/packages/effect/src/unstable/http/HttpRouter.ts:1221–1270  ·  view source on GitHub ↗
(
  appLayer: Layer.Layer<A, E, R>,
  options?: {
    readonly routerConfig?: Partial<FindMyWay.RouterConfig> | undefined
    readonly disableLogger?: boolean | undefined
    readonly disableListenLog?: boolean
    /**
     * Middleware to apply to the HTTP server.
     *
     * **Gotchas**
     *
     * This middleware is applied to the entire HTTP server chain, including the
     * sending of the response. Changes to the response are not reflected in the
     * final response sent to the client. Use `HttpRouter.middleware` when
     * middleware must modify the response.
     */
    readonly middleware?: (
      effect: Effect.Effect<
        HttpServerResponse.HttpServerResponse,
        Request.Only<"Error", R> | Request.Only<"GlobalError", R> | HttpServerError.HttpServerError,
        | Scope.Scope
        | HttpServerRequest.HttpServerRequest
        | Request.Only<"Requires", R>
        | Request.Only<"GlobalRequires", R>
      >
    ) => Effect.Effect<HttpServerResponse.HttpServerResponse, HE, HR>
  }
)

Source from the content-addressed store, hash-verified

1219 Effect.provideContext(effect, services) as Effect.Effect<
1220 HttpServerResponse.HttpServerResponse,
1221 Types.unhandled
1222 >
1223 })).layer
1224 )
1225
1226/**
1227 * Runs the provided application layer as an HTTP server.
1228 *
1229 * @category layers
1230 * @since 4.0.0
1231 */
1232export const serve = <A, E, R, HE, HR = Request.Only<"Requires", R> | Request.Only<"GlobalRequires", R>>(
1233 appLayer: Layer.Layer<A, E, R>,
1234 options?: {
1235 readonly routerConfig?: Partial<FindMyWay.RouterConfig> | undefined
1236 readonly disableLogger?: boolean | undefined
1237 readonly disableListenLog?: boolean
1238 /**
1239 * Middleware to apply to the HTTP server.
1240 *
1241 * **Gotchas**
1242 *
1243 * This middleware is applied to the entire HTTP server chain, including the
1244 * sending of the response. Changes to the response are not reflected in the
1245 * final response sent to the client. Use `HttpRouter.middleware` when
1246 * middleware must modify the response.
1247 */
1248 readonly middleware?: (
1249 effect: Effect.Effect<
1250 HttpServerResponse.HttpServerResponse,
1251 Request.Only<"Error", R> | Request.Only<"GlobalError", R> | HttpServerError.HttpServerError,
1252 | Scope.Scope
1253 | HttpServerRequest.HttpServerRequest
1254 | Request.Only<"Requires", R>
1255 | Request.Only<"GlobalRequires", R>
1256 >
1257 ) => Effect.Effect<HttpServerResponse.HttpServerResponse, HE, HR>
1258 }
1259): Layer.Layer<
1260 A,
1261 Request.Without<E>,
1262 HttpServer.HttpServer | Exclude<Request.Without<R> | Exclude<HR, GlobalProvided>, HttpRouter>
1263> => {
1264 let middleware: any = options?.middleware
1265 if (options?.disableLogger !== true) {
1266 middleware = middleware ? compose(middleware, HttpMiddleware.logger) : HttpMiddleware.logger
1267 }
1268 const RouterLayer = options?.routerConfig
1269 ? Layer.provide(layer, Layer.succeed(RouterConfig)(options.routerConfig))
1270 : layer
1271 return Effect.gen(function*() {
1272 const router = yield* HttpRouter
1273 const handler = router.asHttpEffect()

Callers

nothing calls this directly

Calls 4

composeFunction · 0.90
pipeMethod · 0.65
provideMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…