t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Lambda/HttpServer.fixture.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

61 lines
1.7 KiB
TypeScript

import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
export const TestHttpEffect = Effect.gen(function* () {
const request = yield* HttpServerRequest;
const url = new URL(request.originalUrl);
const pathname = url.pathname;
if (request.method === "GET" && pathname === "/inspect") {
return yield* HttpServerResponse.json({
method: request.method,
url: request.url,
originalUrl: request.originalUrl,
host: request.headers.host,
protocol: request.headers["x-forwarded-proto"],
requestId: request.headers["x-request-id"],
remoteAddress: Option.getOrUndefined(request.remoteAddress),
query: Object.fromEntries(url.searchParams.entries()),
cookies: request.cookies,
});
}
if (request.method === "POST" && pathname === "/jobs") {
const payload = (yield* request.json) as { content: string };
const response = yield* HttpServerResponse.json(
{
method: request.method,
url: request.url,
payload,
},
{
status: 201,
headers: {
"x-handler": "lambda-http",
},
},
);
return HttpServerResponse.setCookieUnsafe(
response,
"job-session",
"created",
{
httpOnly: true,
path: "/",
},
);
}
if (request.method === "GET" && pathname === "/binary") {
return HttpServerResponse.uint8Array(new TextEncoder().encode("alchemy"), {
headers: {
"content-type": "application/octet-stream",
},
});
}
return HttpServerResponse.text("Not found", { status: 404 });
});