Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
wisp.place
1import { serve } from 'bun';
2import app from './server';
3import { FirehoseWorker } from './lib/firehose';
4import { DNSVerificationWorker } from './lib/dns-verification-worker';
5import { mkdirSync, existsSync } from 'fs';
6
7const PORT = process.env.PORT || 3001;
8const CACHE_DIR = './cache/sites';
9
10// Ensure cache directory exists
11if (!existsSync(CACHE_DIR)) {
12 mkdirSync(CACHE_DIR, { recursive: true });
13 console.log('Created cache directory:', CACHE_DIR);
14}
15
16// Start firehose worker
17const firehose = new FirehoseWorker((msg, data) => {
18 console.log(msg, data);
19});
20
21firehose.start();
22
23// Start DNS verification worker (runs every hour)
24const dnsVerifier = new DNSVerificationWorker(
25 60 * 60 * 1000, // 1 hour
26 (msg, data) => {
27 console.log('[DNS Verifier]', msg, data || '');
28 }
29);
30
31dnsVerifier.start();
32
33// Add health check endpoint
34app.get('/health', (c) => {
35 const firehoseHealth = firehose.getHealth();
36 const dnsVerifierHealth = dnsVerifier.getHealth();
37 return c.json({
38 status: 'ok',
39 firehose: firehoseHealth,
40 dnsVerifier: dnsVerifierHealth,
41 });
42});
43
44// Add manual DNS verification trigger (for testing/admin)
45app.post('/admin/verify-dns', async (c) => {
46 try {
47 await dnsVerifier.trigger();
48 return c.json({
49 success: true,
50 message: 'DNS verification triggered',
51 });
52 } catch (error) {
53 return c.json({
54 success: false,
55 error: error instanceof Error ? error.message : String(error),
56 }, 500);
57 }
58});
59
60// Start HTTP server
61const server = serve({
62 port: PORT,
63 fetch: app.fetch,
64});
65
66console.log(`
67Wisp Hosting Service
68
69Server: http://localhost:${PORT}
70Health: http://localhost:${PORT}/health
71Cache: ${CACHE_DIR}
72Firehose: Connected to Jetstream
73DNS Verifier: Checking every hour
74`);
75
76// Graceful shutdown
77process.on('SIGINT', () => {
78 console.log('\n🛑 Shutting down...');
79 firehose.stop();
80 dnsVerifier.stop();
81 server.stop();
82 process.exit(0);
83});
84
85process.on('SIGTERM', () => {
86 console.log('\n🛑 Shutting down...');
87 firehose.stop();
88 dnsVerifier.stop();
89 server.stop();
90 process.exit(0);
91});