Skip to content

Commit

Permalink
Added websocket ping and prom-client
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpapineau committed Sep 27, 2023
1 parent 4c94586 commit 5fe6d89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Bun.serve<{key: string}>({

// verify request
const msg = Buffer.from(timestamp + body);
const isVerified = await verify(msg, signature, PUBLIC_KEY);
const isVerified = verify(msg, signature, PUBLIC_KEY);
if (!isVerified) return new Response("invalid request signature", { status: 401 });

// publish message to subscribers
Expand Down Expand Up @@ -81,6 +81,11 @@ Bun.serve<{key: string}>({
},
message(ws, message) {
const moduleHash = String(message);
if ( moduleHash === "PING" ) {
ws.send("PONG");
console.log('PONG', {key: ws.data.key, remoteAddress: ws.remoteAddress});
return;
}
if ( !moduleHashes.has(moduleHash) ) {
ws.send(`❌ ModuleHash ${moduleHash} not found.`);
console.log('moduleHash not found', {key: ws.data.key, remoteAddress: ws.remoteAddress, moduleHash});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
},
"dependencies": {
"dotenv": "latest",
"prom-client": "^14.2.0",
"tweetnacl": "latest"
},
"devDependencies": {
"bun-types": "latest",
"typescript": "latest"
}
}
}
4 changes: 4 additions & 0 deletions src/prometheus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import client, { Counter, Gauge } from 'prom-client';

export const registry = new client.Registry();
export { client };

0 comments on commit 5fe6d89

Please sign in to comment.