t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Neon/fixtures/function-native.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

38 lines
1.3 KiB
TypeScript

export default {
async fetch(request: Request) {
const path = new URL(request.url).pathname;
if (path === "/echo")
return new Response(request.body, {
headers: { "content-type": "application/octet-stream" },
});
if (path === "/env")
return Response.json({
value: process.env.FUNCTION_TEST_VALUE,
removed: process.env.FUNCTION_TEST_REMOVED,
hasDatabase: !!process.env.DATABASE_URL,
hasAccountKey: !!process.env.NEON_API_KEY,
});
if (path === "/cookies") {
const headers = new Headers();
headers.append("set-cookie", "one=1; Path=/");
headers.append("set-cookie", "two=2; Path=/");
return new Response("cookies", { headers });
}
if (path === "/stream")
return new Response(
new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode("first\n"));
controller.enqueue(new TextEncoder().encode("second\n"));
controller.close();
},
}),
{ headers: { "content-type": "text/event-stream" } },
);
if (path === "/failure")
throw new Error("intentional function fixture failure");
if (path === "/empty") return new Response(null, { status: 204 });
console.log("neon-function-native-request");
return new Response("native-v1");
},
};