-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.ts
44 lines (39 loc) · 1.41 KB
/
server.ts
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
40
41
42
43
44
import * as Earthstar from "https://deno.land/x/[email protected]/mod.ts";
import { DocDriverSqliteFfi } from "https://deno.land/x/[email protected]/src/replica/doc_drivers/sqlite_ffi.ts";
// If FLY_APP_NAME isn't set, we're running locally.
const FLY_APP_NAME = Deno.env.get("FLY_APP_NAME");
// Start the server.
console.log("Starting up server...");
const server = new Earthstar.Server([
// Populate with shares from the a known shares list.
new Earthstar.ExtensionKnownShares({
knownSharesPath: "known_shares.json",
onCreateReplica: (shareAddress) => {
return new Earthstar.Replica(
{
driver: {
docDriver: new DocDriverSqliteFfi({
share: shareAddress,
filename: `./data/${shareAddress}.sql`,
mode: "create-or-open",
}),
attachmentDriver: new Earthstar.AttachmentDriverFilesystem(
`./data/${shareAddress}_attachments`,
),
},
},
);
},
}),
// Add websocket syncing at /earthstar-api/v2
new Earthstar.ExtensionSyncWeb({
path: "/sync",
}),
], { port: 8080 });
console.log('server', server);
// Use the presence of FLY_APP_NAME to figure out the URL for this server.
const hostname = FLY_APP_NAME
? `wss://${FLY_APP_NAME}.fly.dev/`
: "ws://localhost:8080/";
// Log a helpful message about where to sync.
console.log(`Sync with this server at ${hostname}sync`);