forked from hasundue/denopendabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
29 lines (23 loc) · 970 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { serve } from "https://deno.land/std@0.183.0/http/server.ts";
import { Hono } from "https://deno.land/x/hono@v3.1.5/mod.ts";
import { deployment, location } from "./app/deployments.ts";
import { handler } from "./app/webhooks.ts";
const app = new Hono();
// copy and transfer all requests to the staging deployment
app.use("*", async (context, next) => {
const deploy = await deployment();
console.debug(`🏠 deployment: ${deploy}`);
if (deploy === "production") {
const staging = await location("staging");
await fetch(staging + "/api/github/webhooks", context.req.raw.clone());
console.debug(`✈️ transfered the request to ${staging}`);
}
await next();
});
app.get("/", (context) => context.text("Hello, I'm Denopendabot!"));
// handle webhooks with octokit
app.post("/api/github/webhooks", async (context) => {
await handler(context.req);
return context.json(null, 200);
});
await serve(app.fetch, { onListen: () => {} });