From 4c9458643bb8c9460e7aced0dc94cc1314c546b4 Mon Sep 17 00:00:00 2001 From: Samuel Papineau Date: Wed, 27 Sep 2023 14:23:04 -0400 Subject: [PATCH] Handle ping POST requests and Websocket pings --- index.ts | 8 +++++++- src/sqlite.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 45bc1db..caf90e7 100644 --- a/index.ts +++ b/index.ts @@ -53,7 +53,13 @@ Bun.serve<{key: string}>({ if (!isVerified) return new Response("invalid request signature", { status: 401 }); // publish message to subscribers - console.log(JSON.parse(body)) + + if (JSON.parse(body).message == "PING"){ + const message = JSON.parse(body).message; + const response = server.publish(message, body); + console.log('server.publish', {response, message}); + return new Response("OK"); + } const { clock, manifest } = JSON.parse(body); const { moduleHash } = manifest; moduleHashes.add(moduleHash); diff --git a/src/sqlite.ts b/src/sqlite.ts index c8cfe4d..7f7dc2c 100644 --- a/src/sqlite.ts +++ b/src/sqlite.ts @@ -1,4 +1,4 @@ -function create(db){ +function create(db: any){ db.query(`create table if not exists data (moduleHash text primary key)`).run(); }