Skip to content

Commit

Permalink
add server debugging for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhouweling committed Nov 5, 2024
1 parent fbe5508 commit 65369b9
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,43 @@ router.get("/", (_request, env: Env) => {
return new Response(`👋 ${env.DISCORD_APP_ID}`);
});

router.post("/interactions", async (request, env: Env) => {
const services = installServices({ env });
const { discordService } = services;
const commands = getCommands(services);
discordService.setCommands(commands);

const { isValid, interaction } = await discordService.verifyDiscordRequest(request);
if (!isValid || !interaction) {
return new Response("Bad request signature.", { status: 401 });
router.get("/test", async (_request, env: Env) => {
try {
console.log("test called, awaiting timeout...");
await new Promise((resolve) => {
setTimeout(() => {
resolve(undefined);
}, 5000);
});
console.log("timeout completed, returning response");
return new Response(`👋 ${env.DISCORD_APP_ID}`);
} catch (error) {
console.error(error);

return new Response("Internal error", { status: 500 });
}
});

router.post("/interactions", async (request, env: Env) => {
try {
const services = installServices({ env });
const { discordService } = services;
const commands = getCommands(services);
discordService.setCommands(commands);

const response = await discordService.handleInteraction(interaction);
const { isValid, interaction } = await discordService.verifyDiscordRequest(request);
if (!isValid || !interaction) {
return new Response("Bad request signature.", { status: 401 });
}

return response;
const response = await discordService.handleInteraction(interaction);

return response;
} catch (error) {
console.error(error);

return new Response("Internal error", { status: 500 });
}
});
router.all("*", () => new Response("Not Found.", { status: 404 }));

Expand Down

0 comments on commit 65369b9

Please sign in to comment.