Skip to content

Commit

Permalink
implements list-events script, accepts URLSearchParams as input
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrosGounis committed Oct 3, 2024
1 parent 79baff9 commit 680d212
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"deploy": "wrangler publish",
"dev": "wrangler dev --env dev",
"prod": "wrangler dev --env production",
"test": "vitest"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/events/handle-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function handleEvents(request: Request, env: Env, _ctx: ExecutionCo
const url = new URL(request.url)

const eventId = url.searchParams.get('eventId')
const data = Object.fromEntries(url.searchParams);

if (!eventId) {
return new Response("missing event id", { status: 400 })
Expand All @@ -26,9 +27,8 @@ export async function handleEvents(request: Request, env: Env, _ctx: ExecutionCo
user_agent: request.headers.get('User-Agent'),
timestamp,
domain,
event_id: eventId
...data,
}))

return new Response('ok', { status: 200, headers: HEADERS });
}

}
11 changes: 11 additions & 0 deletions src/events/list-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Env } from "../../worker-configuration";

export async function handleEvents(request: Request, env: Env) {
const prefix = 'event/';

const listResult = await env.EVENTS.list({ prefix });

return new Response(JSON.stringify(listResult.keys, null, 2), {
headers: { 'Content-Type': 'application/json' },
});
}
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ routes = [
{ pattern = "services.ghostnet.kukai.app", custom_domain = true }
]
kv_namespaces = [
{ binding = "EVENTS", id = "21597de8ef20463ab9b2ac167a4f3553", preview_id = "262be040e83142458669f91cfe130e75" }
{ binding = "EVENTS", id = "21597de8ef20463ab9b2ac167a4f3553", preview_id = "21597de8ef20463ab9b2ac167a4f3553" }
]

0 comments on commit 680d212

Please sign in to comment.