-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { BodySchema } from "../schemas.js"; | ||
import { handleSinkRequest } from "../clickhouse/handleSinkRequest.js"; | ||
import { sink_request_errors, sink_requests } from "../prometheus.js"; | ||
import { BodySchema } from "../schemas.js"; | ||
import signatureEd25519 from "../webhook/signatureEd25519.js"; | ||
|
||
export default async function (req: Request) { | ||
// validate Ed25519 signature | ||
const text = await req.text(); | ||
const signatureError = await signatureEd25519(req, text); | ||
if ( signatureError ) return signatureError; | ||
// validate Ed25519 signature | ||
const text = await req.text(); | ||
const signatureError = await signatureEd25519(req, text); | ||
if (signatureError) return signatureError; | ||
|
||
// parse POST body payload | ||
// parse POST body payload | ||
try { | ||
const body = BodySchema.parse(JSON.parse(text)); | ||
if ( "message" in body ) { | ||
if (body.message === "PING") return new Response("OK"); | ||
return new Response("invalid body", { status: 400 }); | ||
|
||
if ("message" in body) { | ||
if (body.message === "PING") return new Response("OK"); | ||
return new Response("invalid body", { status: 400 }); | ||
} | ||
|
||
return handleSinkRequest(body); | ||
} catch { | ||
sink_request_errors?.inc(); | ||
} finally { | ||
sink_requests?.inc(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters