diff --git a/src/server.mts b/src/server.mts index 08ac315..6257fda 100644 --- a/src/server.mts +++ b/src/server.mts @@ -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 }));