generated from hasundue/template-deno
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.ts
31 lines (26 loc) · 1.04 KB
/
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
30
31
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { Hono } from "https://deno.land/x/[email protected]/mod.ts";
import { getDeployEnvUrl, getThisDeployEnv } 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) => {
if (await getThisDeployEnv() === "Production") {
console.debug(`🏠 deployment: Production`);
const staging = await getDeployEnvUrl("Preview");
if (staging) {
await fetch(staging + "/api/github/webhooks", context.req.raw.clone());
console.debug(`✈️ transfered the request to ${staging}`);
}
} else {
console.debug(`🏠 deployment: Preview`);
}
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: () => {} });