-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookies.ts
33 lines (25 loc) · 966 Bytes
/
cookies.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { Context, Config } from "@netlify/edge-functions";
export default async (request: Request, context: Context) => {
const url = new URL(request.url);
switch (url.searchParams.get("action")) {
case "set":
context.cookies.set({
name: "action",
value: "hello",
});
return new Response('Cookie value has been set. Reload this page without the "action" parameter to see it.');
case "clear":
context.cookies.delete("action");
return new Response(
'Cookie value has been cleared. Reload this page without the "action" parameter to see the new state.',
);
}
const value = context.cookies.get("action");
const message = value
? `Cookie value is "${value}". You can clear it by using "?action=clear".`
: 'Cookie has not been set. You can do so by adding "?action=set" to the URL.';
return new Response(message);
};
export const config: Config = {
path: "/cookies",
};