-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
39 lines (35 loc) · 1.5 KB
/
Copy pathserver.ts
File metadata and controls
39 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Production entry point. Wraps the adapter-node build's request handler
// with a raw http.Server so the /ws Yjs endpoint can share the same process
// and port — the one-process architecture in docs/technical-design.md §1.
// Run with `npm run build && npm start`.
import { createServer } from 'node:http';
// @ts-expect-error -- generated by `npm run build`, not present at typecheck time
import { handler } from './build/handler.js';
import { attachYjsWebSocket } from './src/lib/server/attach-ws.js';
import { getInstanceWorkspaceId } from './src/lib/server/instance.js';
const port = Number(process.env.PORT ?? 3000);
const server = createServer(handler);
attachYjsWebSocket(server);
// DATABASE_URL is usually a local sqlite file path, but nothing prevents it
// from being a connection string with embedded credentials — strip
// userinfo before it ever reaches a log line.
function sanitizeDbPath(raw: string): string {
try {
const url = new URL(raw);
url.username = '';
url.password = '';
return url.toString();
} catch {
return raw;
}
}
server.listen(port, () => {
// Instance/workspace identity and DB path, not secrets — makes the
// isolation boundary #111 introduces observable at a glance rather than
// something only inferrable from DATABASE_URL (#111).
const dbPath = sanitizeDbPath(process.env.DATABASE_URL ?? '.data/compendium.db');
console.log(
`Compendium listening on http://localhost:${port} ` +
`(instance/workspace: ${getInstanceWorkspaceId()}, db: ${dbPath})`
);
});