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 aa1a051
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
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 aa1a051

Please sign in to comment.