1import * as Effect from "effect/Effect";
2import { HttpServerRequest } from "effect/http/HttpServerRequest";
3import * as HttpServerResponse from "effect/http/HttpServerResponse";
4
5/**
6 * The effectful MicroVM server, shared verbatim by the bun and node effectful
7 * images so the only thing that differs between them is the JS runtime. Exposes
8 * a raw `fetch` handler (with an `/echo` route) and a typed RPC `hello` method.
9 */
10export const effectfulImpl = Effect.gen(function* () {
11 return {
12 fetch: Effect.gen(function* () {
13 const request = yield* HttpServerRequest;
14 const url = new URL(request.url, "http://microvm");
15 if (url.pathname === "/echo") {
16 return yield* HttpServerResponse.json({
17 message: url.searchParams.get("message") ?? "",
18 });
19 }
20 return HttpServerResponse.text("hello from effectful microvm");
21 }),
22 hello: (message: string) => Effect.succeed(`hello, ${message}!`),
23 };
24});