@@ -2,6 +2,8 @@ import { createRouter, Response } from "fets";
22import { App } from "uWebSockets.js" ;
33import { isAddress } from "viem" ;
44import { sendWebhook } from "./send-webhook.mjs" ;
5+ import { registry } from "./prometheus.mjs" ;
6+ import { spawn } from "node:child_process" ;
57
68// Creating a new router
79const router = createRouter ( {
@@ -69,44 +71,58 @@ const router = createRouter({
6971 if ( startBlock == null ) {
7072 return Response . json (
7173 { message : "startBlock is required" } ,
72- { status : 400 } ,
74+ { status : 400 }
7375 ) ;
7476 }
7577
7678 if ( ! contractAddress ) {
7779 return Response . json (
7880 { message : "contractAddress is required" } ,
79- { status : 400 } ,
81+ { status : 400 }
8082 ) ;
8183 }
8284
8385 if ( ! substreamsToken ) {
8486 return Response . json (
8587 { message : "substreamsToken is required" } ,
86- { status : 400 } ,
88+ { status : 400 }
8789 ) ;
8890 }
8991
9092 if ( ! isAddress ( contractAddress ) ) {
9193 return Response . json (
9294 { message : "contractAddress is invalid" } ,
93- { status : 400 } ,
95+ { status : 400 }
9496 ) ;
9597 }
9698
9799 // Sending the webhook
98- sendWebhook ( {
99- appId,
100- startBlock,
101- contractAddress,
102- token : substreamsToken ,
103- } ) ;
100+ await Promise . all ( [
101+ sendWebhook ( {
102+ appId,
103+ startBlock,
104+ contractAddress : contractAddress . toLowerCase ( ) ,
105+ token : substreamsToken ,
106+ } ) ,
107+ ] ) ;
104108
105109 // If the status code is not specified, it defaults to 200
106110 return Response . json ( {
107111 message : "Webhook registered" ,
108112 } ) ;
109113 } ,
114+ } )
115+ . route ( {
116+ path : "/metrics" ,
117+ method : "GET" ,
118+ async handler ( ) {
119+ const metrics = await registry . metrics ( ) ;
120+ return new Response ( metrics , {
121+ headers : {
122+ "Content-Type" : registry . contentType ,
123+ } ,
124+ } ) ;
125+ } ,
110126 } ) ;
111127
112128App ( )
0 commit comments