| 225 | * @since 4.0.0 |
| 226 | */ |
| 227 | export 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 | |
| 251 | const defaultMimeTypes: Record<string, string> = { |
| 252 | html: "text/html; charset=utf-8", |