Skip to content

Instantly share code, notes, and snippets.

@mchlggr
Forked from Fredx87/index.ts
Created June 13, 2025 04:41
Show Gist options
  • Save mchlggr/484b2541bd23a6c3e2fbd4f9cefca20f to your computer and use it in GitHub Desktop.
Save mchlggr/484b2541bd23a6c3e2fbd4f9cefca20f to your computer and use it in GitHub Desktop.

Revisions

  1. @Fredx87 Fredx87 created this gist Jan 6, 2024.
    28 changes: 28 additions & 0 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import * as Http from "@effect/platform/HttpServer";
    import { Effect } from "effect";
    import * as S from "@effect/schema/Schema";

    const HttpLive = Http.router.empty.pipe(
    Http.router.get("/", Http.response.text("Hello World")),
    Http.router.get(
    "/todo/:id",
    Effect.gen(function* ($) {
    const { id } = yield* $(
    Http.router.schemaPathParams(S.struct({ id: S.NumberFromString })),
    );
    return yield* $(Http.response.text(`Todo ${id}`));
    }),
    ),
    Http.router.all("*", Http.response.empty({ status: 404 })),
    Http.router.catchAll((e) => {
    console.log(e);
    return Http.response.empty({ status: 400 });
    }),
    Http.app.toWebHandler,
    );

    export default {
    async fetch(request: Request) {
    return await HttpLive(request);
    },
    };