-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.mjs
41 lines (37 loc) · 1.16 KB
/
index.mjs
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,
ReplicaDriverFs,
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({
// Set the shares you want your replica server to have at data/known_shares.json
knownSharesPath: "./.data/known_shares.json",
// Persist share replica data to ./.data
onCreateReplica: (shareAddress) => {
return new Replica({
driver: new ReplicaDriverFs(
shareAddress,
`./.data/${shareAddress}/`,
),
});
},
}),
// Allow syncing at root path
new ExtensionSyncWeb({ server: nodeServer }),
], { port: 3000, server: nodeServer });
if (process.env.PROJECT_DOMAIN) {
console.log(
`Sync with this server at https://${process.env.PROJECT_DOMAIN}.glitch.me/`,
);
} else {
console.log(`Sync with this server at http://localhost:3000`);
}