diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dbdc51d..4faecc7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,5 +37,5 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: guilt-spark-build-${{ github.sha }} + name: guilt-spark-build-${{ github.head_ref || github.ref_name }} path: ./dist diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 459d026..f661871 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,7 +32,7 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v4 with: - name: guilt-spark-build-${{ github.event.workflow_run.head_commit.id }} + name: guilt-spark-build-${{ github.event.workflow_run.head_branch }} run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} 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 }));