the statusphere demo reworked into a vite/react app in a monorepo

configurable jetstream instance

Changed files
+8 -14
packages
appview
src
ingestors
lib
client
+7 -3
packages/appview/src/ingestors/jetstream.ts
··· 3 3 import WebSocket from 'ws' 4 4 5 5 import type { Database } from '#/db' 6 + import { env } from '#/lib/env' 6 7 7 8 export async function createJetstreamIngester(db: Database) { 8 9 const logger = pino({ name: 'jetstream ingestion' }) ··· 19 20 let lastCursorWrite = 0 20 21 21 22 return new Jetstream<XyzStatusphereStatus.Record>({ 23 + instanceUrl: env.JETSTREAM_INSTANCE, 22 24 logger, 23 25 cursor: cursor?.seq || undefined, 24 26 setCursor: async (seq) => { ··· 55 57 ) 56 58 if (!validatedRecord.success) return 57 59 58 - // Store the status in our SQLite 59 60 await db 60 61 .insertInto('status') 61 62 .values({ ··· 73 74 ) 74 75 .execute() 75 76 } else if (evt.commit.operation === 'delete') { 76 - // Remove the status from our SQLite 77 77 await db.deleteFrom('status').where('uri', '=', uri).execute() 78 78 } 79 79 }, ··· 85 85 } 86 86 87 87 export class Jetstream<T> { 88 + private instanceUrl: string 88 89 private logger: pino.Logger 89 90 private handleEvent: (evt: JetstreamEvent<T>) => Promise<void> 90 91 private onError: (err: unknown) => void ··· 95 96 private wantedCollections: string[] 96 97 97 98 constructor({ 99 + instanceUrl, 98 100 logger, 99 101 cursor, 100 102 setCursor, ··· 102 104 onError, 103 105 wantedCollections, 104 106 }: { 107 + instanceUrl: string 105 108 logger: pino.Logger 106 109 cursor?: number 107 110 setCursor?: (seq: number) => Promise<void> ··· 109 112 onError: (err: any) => void 110 113 wantedCollections: string[] 111 114 }) { 115 + this.instanceUrl = instanceUrl 112 116 this.logger = logger 113 117 this.cursor = cursor 114 118 this.setCursor = setCursor ··· 123 127 if (this.cursor !== undefined) { 124 128 params.append('cursor', this.cursor.toString()) 125 129 } 126 - return `wss://jetstream.mozzius.dev/subscribe?${params.toString()}` 130 + return `${this.instanceUrl}/subscribe?${params.toString()}` 127 131 } 128 132 129 133 start() {
+1
packages/appview/src/lib/env.ts
··· 15 15 COOKIE_SECRET: str({ devDefault: '0'.repeat(32) }), 16 16 SERVICE_DID: str({ default: undefined }), 17 17 PUBLIC_URL: str({ devDefault: '' }), 18 + JETSTREAM_INSTANCE: str({ default: 'wss://jetstream.mozzius.dev' }), 18 19 })
-11
packages/client/vite.config.ts
··· 21 21 '^/(xrpc|oauth|client-metadata\.json)/.*': { 22 22 target: 'http://localhost:3001', 23 23 changeOrigin: true, 24 - configure: (proxy, _options) => { 25 - proxy.on('error', (err, _req, _res) => { 26 - console.log('PROXY ERROR', err); 27 - }); 28 - proxy.on('proxyReq', (proxyReq, req, _res) => { 29 - console.log('PROXY REQUEST', req.method, req.url); 30 - }); 31 - proxy.on('proxyRes', (proxyRes, req, _res) => { 32 - console.log('PROXY RESPONSE', req.method, req.url, proxyRes.statusCode); 33 - }); 34 - }, 35 24 }, 36 25 }, 37 26 },