Skip to content

Commit 6dab963

Browse files
committed
feat: set x-webhook-filter-deploy on all requests
1 parent d88eded commit 6dab963

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/main.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import config from "./config.ts";
66
import { contextMiddleware, getRequestLog } from "./context.ts";
77
import { hasKey, verify } from "./crypto.ts";
88
import handler from "./handler.ts";
9+
import { setMetaHeader } from "./util.ts";
910

1011
const app = new Hono();
1112

@@ -14,6 +15,12 @@ app.use(contextMiddleware);
1415
// use context's requestlog for server logs
1516
app.use(logger((...args) => getRequestLog().log(...args)));
1617

18+
// add deploy header to responses
19+
app.use(async (c, next) => {
20+
await next();
21+
setMetaHeader(c, "deploy", config.deployId);
22+
});
23+
1724
if (config.mainRedirect) {
1825
app.get("/", (c) => {
1926
return c.redirect(config.mainRedirect!);
@@ -38,12 +45,8 @@ app.post("/:id/:token", async (c) => {
3845
res = new Response(res.body, res);
3946

4047
// set metadata headers
41-
meta = {
42-
"deploy": config.deployId,
43-
...meta,
44-
};
4548
for (const [key, value] of Object.entries(meta)) {
46-
res.headers.set(`x-webhook-filter-${key}`, value);
49+
setMetaHeader(c, key, value);
4750
}
4851

4952
// remove other headers that don't make sense here

src/util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Context } from "@hono/hono";
2+
13
export function parseBool(s: string): boolean {
24
return ["1", "true", "on", "y", "yes"].includes(s.toLowerCase());
35
}
@@ -51,3 +53,7 @@ export function requestLog(deliveryId: string | undefined) {
5153
}
5254

5355
export type RequestLog = ReturnType<typeof requestLog>;
56+
57+
export function setMetaHeader(c: Context, key: string, value: string): void {
58+
c.res.headers.set(`x-webhook-filter-${key}`, value);
59+
}

0 commit comments

Comments
 (0)