1export default {
2 async fetch(request: Request) {
3 const path = new URL(request.url).pathname;
4 if (path === "/echo")
5 return new Response(request.body, {
6 headers: { "content-type": "application/octet-stream" },
7 });
8 if (path === "/env")
9 return Response.json({
10 value: process.env.FUNCTION_TEST_VALUE,
11 removed: process.env.FUNCTION_TEST_REMOVED,
12 hasDatabase: !!process.env.DATABASE_URL,
13 hasAccountKey: !!process.env.NEON_API_KEY,
14 });
15 if (path === "/cookies") {
16 const headers = new Headers();
17 headers.append("set-cookie", "one=1; Path=/");
18 headers.append("set-cookie", "two=2; Path=/");
19 return new Response("cookies", { headers });
20 }
21 if (path === "/stream")
22 return new Response(
23 new ReadableStream({
24 start(controller) {
25 controller.enqueue(new TextEncoder().encode("first\n"));
26 controller.enqueue(new TextEncoder().encode("second\n"));
27 controller.close();
28 },
29 }),
30 { headers: { "content-type": "text/event-stream" } },
31 );
32 if (path === "/failure")
33 throw new Error("intentional function fixture failure");
34 if (path === "/empty") return new Response(null, { status: 204 });
35 console.log("neon-function-native-request");
36 return new Response("native-v1");
37 },
38};