MCPcopy Create free account
hub / github.com/Effect-TS/effect / layer

Function layer

packages/effect/src/unstable/http/HttpStaticServer.ts:227–249  ·  view source on GitHub ↗
(options: {
  readonly root: string
  readonly index?: string | undefined
  readonly spa?: boolean | undefined
  readonly cacheControl?: string | undefined
  readonly mimeTypes?: Record<string, string> | undefined
  readonly prefix?: string | undefined
})

Source from the content-addressed store, hash-verified

225 * @since 4.0.0
226 */
227export const layer = (options: {
228 readonly root: string
229 readonly index?: string | undefined
230 readonly spa?: boolean | undefined
231 readonly cacheControl?: string | undefined
232 readonly mimeTypes?: Record<string, string> | undefined
233 readonly prefix?: string | undefined
234}): Layer.Layer<
235 never,
236 PlatformError,
237 HttpRouter.HttpRouter | FileSystem.FileSystem | Path.Path | HttpPlatform.HttpPlatform
238> =>
239 Layer.effectDiscard(Effect.gen(function*() {
240 const router = yield* HttpRouter.HttpRouter
241 const handler = (yield* make(options)).pipe(
242 Effect.catch(HttpServerRespondable.toResponse)
243 )
244 if (options.prefix !== undefined) {
245 yield* router.prefixed(options.prefix).add("GET", "/*", handler)
246 return
247 }
248 yield* router.add("GET", "/*", handler)
249 }))
250
251const defaultMimeTypes: Record<string, string> = {
252 html: "text/html; charset=utf-8",

Callers

nothing calls this directly

Calls 3

makeFunction · 0.70
pipeMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected