forked from earthstar-project/earthstar-server-fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (38 loc) · 1.18 KB
/
index.js
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
import { createServer } from "http";
import { Replica, setGlobalCryptoDriver } from "earthstar";
import {
CryptoDriverChloride,
ExtensionKnownShares,
ExtensionSyncWeb,
AttachmentDriverFilesystem,
Server,
} from "earthstar/node";
// Use the fastest crypto drive available for Node.
setGlobalCryptoDriver(CryptoDriverChloride);
// Create underlying HTTP server to be used by Earthstar server.
const nodeServer = createServer();
new Server(
[
new ExtensionKnownShares({
// Populate with shares from the a known shares list.
knownSharesPath: "known_shares.json",
onCreateReplica: (shareAddress) => {
return new Replica({
driver: {
docDriver: new Earthstar.DocDriverSqliteFfi({
share: shareAddress,
filename: `./data/${shareAddress}.sql`,
mode: "create-or-open",
}),
attachmentDriver: new AttachmentDriverFilesystem(
`./data/${shareAddress}_attachments`
),
},
});
},
}),
new ExtensionSyncWeb({ server: nodeServer, path: "/sync" }),
],
// @TODO Figure out how to get the free port
{ port: 3000, server: nodeServer }
);