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

Function makeHandler

packages/effect/src/unstable/httpapi/HttpApiSwagger.ts:21–50  ·  view source on GitHub ↗
(options: {
  readonly api: HttpApi.HttpApi<Id, Groups>
})

Source from the content-addressed store, hash-verified

19import * as OpenApi from "./OpenApi.ts"
20
21const makeHandler = <Id extends string, Groups extends HttpApiGroup.Constraint>(options: {
22 readonly api: HttpApi.HttpApi<Id, Groups>
23}) => {
24 const spec = OpenApi.fromApi(options.api)
25 const response = HttpServerResponse.html(`<!DOCTYPE html>
26<html lang="en">
27<head>
28 <meta charset="utf-8" />
29 <meta name="viewport" content="width=device-width, initial-scale=1" />
30 <title>${Html.escape(spec.info.title)} Documentation</title>
31 <style>${internal.css}</style>
32</head>
33<body>
34 <div id="swagger-ui"></div>
35 <script id="swagger-spec" type="application/json">
36 ${Html.escapeJson(spec)}
37 </script>
38 <script>
39 ${internal.javascript}
40 window.onload = () => {
41 window.ui = SwaggerUIBundle({
42 spec: JSON.parse(document.getElementById("swagger-spec").textContent),
43 dom_id: "#swagger-ui",
44 });
45 };
46 </script>
47</body>
48</html>`)
49 return Effect.succeed(response)
50}
51
52/**
53 * Mounts Swagger UI for an `HttpApi` at the configured path, defaulting to

Callers 1

layerFunction · 0.70

Calls 1

succeedMethod · 0.45

Tested by

no test coverage detected