@peerbit/server 5.7.0 → 5.8.1-8f8f903

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/src/aws.d.ts +1 -1
  2. package/dist/src/aws.d.ts.map +1 -1
  3. package/dist/src/aws.js +5 -4
  4. package/dist/src/aws.js.map +1 -1
  5. package/dist/src/cli.d.ts.map +1 -1
  6. package/dist/src/cli.js +10 -15
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/client.d.ts +12 -0
  9. package/dist/src/client.d.ts.map +1 -1
  10. package/dist/src/client.js +9 -1
  11. package/dist/src/client.js.map +1 -1
  12. package/dist/src/domain.d.ts +1 -1
  13. package/dist/src/domain.d.ts.map +1 -1
  14. package/dist/src/domain.js +2 -10
  15. package/dist/src/domain.js.map +1 -1
  16. package/dist/src/nginx-template.conf +0 -18
  17. package/dist/src/peerbit.d.ts.map +1 -1
  18. package/dist/src/peerbit.js +17 -6
  19. package/dist/src/peerbit.js.map +1 -1
  20. package/dist/src/routes.d.ts +1 -0
  21. package/dist/src/routes.d.ts.map +1 -1
  22. package/dist/src/routes.js +1 -0
  23. package/dist/src/routes.js.map +1 -1
  24. package/dist/src/server.d.ts +1 -2
  25. package/dist/src/server.d.ts.map +1 -1
  26. package/dist/src/server.js +31 -1
  27. package/dist/src/server.js.map +1 -1
  28. package/dist/test/api.spec.js.map +1 -1
  29. package/dist/test/domain.integration.spec.js +3 -6
  30. package/dist/test/domain.integration.spec.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/ui/assets/{index-DO8U-NKu.js → index-BQTJHTQs.js} +1 -1
  33. package/dist/ui/index.html +1 -1
  34. package/package.json +89 -89
  35. package/src/aws.ts +6 -5
  36. package/src/cli.ts +14 -20
  37. package/src/client.ts +17 -0
  38. package/src/domain.ts +1 -13
  39. package/src/nginx-template.conf +0 -18
  40. package/src/peerbit.ts +19 -8
  41. package/src/routes.ts +1 -0
  42. package/src/server.ts +37 -4
@@ -23,7 +23,7 @@
23
23
  Learn how to configure a non-root public URL by running `npm run build`.
24
24
  -->
25
25
  <title>Peerbit</title>
26
- <script type="module" crossorigin src="/assets/index-DO8U-NKu.js"></script>
26
+ <script type="module" crossorigin src="/assets/index-BQTJHTQs.js"></script>
27
27
  <link rel="stylesheet" crossorigin href="/assets/index-CIfVvUo9.css">
28
28
  </head>
29
29
 
package/package.json CHANGED
@@ -1,91 +1,91 @@
1
1
  {
2
- "name": "@peerbit/server",
3
- "version": "5.7.0",
4
- "author": "dao.xyz",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/dao-xyz/peerbit"
8
- },
9
- "license": "Apache-2.0",
10
- "type": "module",
11
- "sideEffects": false,
12
- "bin": {
13
- "peerbit": "./dist/src/bin.js"
14
- },
15
- "module": "dist/src/index.js",
16
- "types": "dist/src/index.d.ts",
17
- "exports": {
18
- "import": "./dist/src/index.js"
19
- },
20
- "browser": {
21
- "./dist/src/server.js": "./dist/src/server.browser.js",
22
- "./server.js": "./dist/src/server.browser.js",
23
- "./dist/src/config.js": "./dist/src/config.browser.js",
24
- "./config.js": "./dist/src/config.browser.js",
25
- "./dist/src/remotes.js": "./dist/src/remotes.browser.js",
26
- "./remotes.js": "./dist/src/remotes.browser.js",
27
- "./dist/src/docker.js": "./dist/src/docker.browser.js",
28
- "./docker.js": "./dist/src/docker.browser.js",
29
- "./dist/src/aws.js": "./dist/src/aws.browser.js"
30
- },
31
- "files": [
32
- "dist",
33
- "src",
34
- "src/nginx-template.conf",
35
- "!src/test",
36
- "!src/**/__tests__",
37
- "!lib/**/__tests__",
38
- "patches",
39
- "LICENSE"
40
- ],
41
- "publishConfig": {
42
- "access": "public"
43
- },
44
- "engines": {
45
- "node": ">=18"
46
- },
47
- "eslintConfig": {
48
- "extends": "peerbit",
49
- "parserOptions": {
50
- "project": true,
51
- "sourceType": "module"
52
- },
53
- "ignorePatterns": [
54
- "!.aegir.js",
55
- "test/ts-use",
56
- "*.d.ts"
57
- ]
58
- },
59
- "scripts": {
60
- "clean": "shx rm -rf lib/*",
61
- "build": "yarn clean && yarn build-lib && yarn build-ui",
62
- "build-lib": "tsc -p tsconfig.json",
63
- "build-ui": "cd ../frontend && yarn build && cd ../node",
64
- "postbuild": "cp src/nginx-template.conf dist/src/ && cp -r ../frontend/dist/. dist/ui",
65
- "test": "aegir test --t node",
66
- "lint": "aegir lint"
67
- },
68
- "devDependencies": {
69
- "@peerbit/test-lib": "^0.0.1",
70
- "@peerbit/test-utils": "2.2.0",
71
- "@types/yargs": "17.0.24",
72
- "aws-sdk": "^2.1259.0",
73
- "dotenv": "^16.1.4",
74
- "@types/tmp": "^0.2.3",
75
- "@types/tar-stream": "^3.1.3",
76
- "shx": "^0.3.4"
77
- },
78
- "dependencies": {
79
- "axios": "^1.4.0",
80
- "chalk": "^5.3.0",
81
- "peerbit": "4.2.0",
82
- "yargs": "^17.7.2",
83
- "tar-stream": "^3.1.7",
84
- "tmp": "^0.2.1",
85
- "tty-table": "^4.2.1"
86
- },
87
- "optionalDependencies": {
88
- "@aws-sdk/client-ec2": "^3.390.0",
89
- "@aws-sdk/client-route-53": "^3.391.0"
90
- }
2
+ "name": "@peerbit/server",
3
+ "version": "5.8.1-8f8f903",
4
+ "author": "dao.xyz",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/dao-xyz/peerbit"
8
+ },
9
+ "license": "Apache-2.0",
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "bin": {
13
+ "peerbit": "./dist/src/bin.js"
14
+ },
15
+ "module": "dist/src/index.js",
16
+ "types": "dist/src/index.d.ts",
17
+ "exports": {
18
+ "import": "./dist/src/index.js"
19
+ },
20
+ "browser": {
21
+ "./dist/src/server.js": "./dist/src/server.browser.js",
22
+ "./server.js": "./dist/src/server.browser.js",
23
+ "./dist/src/config.js": "./dist/src/config.browser.js",
24
+ "./config.js": "./dist/src/config.browser.js",
25
+ "./dist/src/remotes.js": "./dist/src/remotes.browser.js",
26
+ "./remotes.js": "./dist/src/remotes.browser.js",
27
+ "./dist/src/docker.js": "./dist/src/docker.browser.js",
28
+ "./docker.js": "./dist/src/docker.browser.js",
29
+ "./dist/src/aws.js": "./dist/src/aws.browser.js"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "src",
34
+ "src/nginx-template.conf",
35
+ "!src/test",
36
+ "!src/**/__tests__",
37
+ "!lib/**/__tests__",
38
+ "patches",
39
+ "LICENSE"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "engines": {
45
+ "node": ">=18"
46
+ },
47
+ "eslintConfig": {
48
+ "extends": "peerbit",
49
+ "parserOptions": {
50
+ "project": true,
51
+ "sourceType": "module"
52
+ },
53
+ "ignorePatterns": [
54
+ "!.aegir.js",
55
+ "test/ts-use",
56
+ "*.d.ts"
57
+ ]
58
+ },
59
+ "scripts": {
60
+ "clean": "shx rm -rf lib/*",
61
+ "build": "yarn clean && yarn build-lib && yarn build-ui",
62
+ "build-lib": "tsc -p tsconfig.json",
63
+ "build-ui": "cd ../frontend && yarn build && cd ../node",
64
+ "postbuild": "cp src/nginx-template.conf dist/src/ && cp -r ../frontend/dist/. dist/ui",
65
+ "test": "aegir test --t node",
66
+ "lint": "aegir lint"
67
+ },
68
+ "devDependencies": {
69
+ "@peerbit/test-lib": "0.0.1-8f8f903",
70
+ "@peerbit/test-utils": "2.2.1-8f8f903",
71
+ "@types/yargs": "17.0.24",
72
+ "aws-sdk": "^2.1259.0",
73
+ "dotenv": "^16.1.4",
74
+ "@types/tmp": "^0.2.3",
75
+ "@types/tar-stream": "^3.1.3",
76
+ "shx": "^0.3.4"
77
+ },
78
+ "dependencies": {
79
+ "axios": "^1.4.0",
80
+ "chalk": "^5.3.0",
81
+ "peerbit": "4.3.0-8f8f903",
82
+ "yargs": "^17.7.2",
83
+ "tar-stream": "^3.1.7",
84
+ "tmp": "^0.2.1",
85
+ "tty-table": "^4.2.1"
86
+ },
87
+ "optionalDependencies": {
88
+ "@aws-sdk/client-ec2": "^3.390.0",
89
+ "@aws-sdk/client-route-53": "^3.391.0"
90
+ }
91
91
  }
package/src/aws.ts CHANGED
@@ -52,17 +52,18 @@ export const createRecord = async (options: {
52
52
  await client.send(cmd);
53
53
  };
54
54
 
55
- const setupUserData = (email: string, grantAccess: PeerId[] = []) => {
55
+ const setupUserData = (grantAccess: PeerId[] = [], serverVersion?: string) => {
56
56
  const peerIdStrings = grantAccess.map((x) => x.toString());
57
57
 
58
58
  // better-sqlite3 force use to install build-essentials for `make` command, TOOD dont bundle better-sqlite3 by default?
59
+ const versionSpec = serverVersion ? `@${serverVersion}` : "";
59
60
  return `#!/bin/bash
60
61
  cd /home/ubuntu
61
62
  curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - &&\
62
63
  sudo apt-get install -y nodejs
63
64
  sudo apt-get install -y build-essential
64
- npm install -g @peerbit/server
65
- sudo peerbit domain test --email ${email}
65
+ npm install -g @peerbit/server${versionSpec}
66
+ sudo peerbit domain test
66
67
  peerbit start ${peerIdStrings.map((key) => `--ga ${key}`)} > log.txt 2>&1 &
67
68
  `;
68
69
  };
@@ -105,11 +106,11 @@ export const AWS_LINUX_ARM_AMIs: Record<string, string> = {
105
106
  };
106
107
  export const launchNodes = async (properties: {
107
108
  region?: string;
108
- email: string;
109
109
  count?: number;
110
110
  size?: "micro" | "small" | "medium" | "large" | "xlarge" | "2xlarge";
111
111
  namePrefix?: string;
112
112
  grantAccess?: PeerId[];
113
+ serverVersion?: string;
113
114
  }): Promise<
114
115
  { instanceId: string; publicIp: string; name: string; region: string }[]
115
116
  > => {
@@ -218,7 +219,7 @@ export const launchNodes = async (properties: {
218
219
  SecurityGroupIds: [securityGroupOut.GroupId!],
219
220
  InstanceType: ("t4g." + (properties.size || "micro")) as any, // TODO types
220
221
  UserData: Buffer.from(
221
- setupUserData(properties.email, properties.grantAccess),
222
+ setupUserData(properties.grantAccess, properties.serverVersion),
222
223
  ).toString("base64"),
223
224
  MinCount: count,
224
225
  MaxCount: count,
package/src/cli.ts CHANGED
@@ -218,11 +218,6 @@ export const cli = async (args?: string[]) => {
218
218
  describe:
219
219
  "Setup a testing domain with SSL (no guarantess on how long the domain will be available)",
220
220
  builder: {
221
- email: {
222
- describe: "Email for Lets encrypt autorenewal messages",
223
- type: "string",
224
- demandOption: true,
225
- },
226
221
  outdir: {
227
222
  describe: "Output path for Nginx config",
228
223
  type: "string",
@@ -237,7 +232,7 @@ export const cli = async (args?: string[]) => {
237
232
  },
238
233
  handler: async (args) => {
239
234
  const domain = await createTestDomain();
240
- await startCertbot(domain, args.email, args.wait);
235
+ await startCertbot(domain, args.wait);
241
236
  exit();
242
237
  },
243
238
  })
@@ -273,11 +268,6 @@ export const cli = async (args?: string[]) => {
273
268
  alias: "sk",
274
269
  type: "string",
275
270
  },
276
- email: {
277
- describe: "Email for Lets encrypt auto-renewal messages",
278
- type: "string",
279
- demandOption: true,
280
- },
281
271
  outdir: {
282
272
  describe: "Output path for Nginx config",
283
273
  type: "string",
@@ -310,12 +300,7 @@ export const cli = async (args?: string[]) => {
310
300
  }
311
301
  : undefined,
312
302
  });
313
- await startCertbot(
314
- args.domain,
315
- args.email,
316
- args.outdir,
317
- args.wait,
318
- );
303
+ await startCertbot(args.domain, args.wait);
319
304
  exit();
320
305
  },
321
306
  })
@@ -386,24 +371,33 @@ export const cli = async (args?: string[]) => {
386
371
  alias: "d",
387
372
  default: getHomeConfigDir(),
388
373
  });
374
+ awsArgs.option("server-version", {
375
+ describe:
376
+ "@peerbit/server version or tag to install on the instance (e.g. 5.7.0-58d3d09)",
377
+ type: "string",
378
+ alias: ["sv"],
379
+ });
389
380
  return awsArgs;
390
381
  },
391
382
  handler: async (args) => {
392
383
  const accessGrant: PeerId[] =
393
- args.access?.length > 0
394
- ? args.access.map((x: any) => peerIdFromString(x))
384
+ args["grant-access"]?.length > 0
385
+ ? (args["grant-access"] as string[]).map((x) =>
386
+ peerIdFromString(x),
387
+ )
395
388
  : [
396
389
  await (
397
390
  await getKeypair(args.directory)
398
391
  ).publicKey.toPeerId(),
399
392
  ];
400
393
  const nodes = await launchNodes({
401
- email: "marcus@dao.xyz",
402
394
  count: args.count,
403
395
  namePrefix: args.name,
404
396
  region: args.region,
405
397
  grantAccess: accessGrant,
406
398
  size: args.size,
399
+ serverVersion:
400
+ (args["server-version"] as string) || undefined,
407
401
  });
408
402
 
409
403
  console.log(
package/src/client.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  REMOTE_API_PORT,
24
24
  RESTART_PATH,
25
25
  SELF_UPDATE_PATH,
26
+ STATS_PATH,
26
27
  STOP_PATH,
27
28
  TRUST_PATH,
28
29
  VERSIONS_PATH,
@@ -132,6 +133,22 @@ export const createClient = async (
132
133
  ).map((x) => multiaddr(x));
133
134
  },
134
135
  },
136
+ stats: {
137
+ get: async (): Promise<{
138
+ connections: { total: number; inbound: number; outbound: number };
139
+ dialQueue: { pending: number };
140
+ }> => {
141
+ const resp = throwIfNot200(
142
+ await axiosInstance.get(endpoint + STATS_PATH, {
143
+ validateStatus,
144
+ }),
145
+ );
146
+ return resp.data as {
147
+ connections: { total: number; inbound: number; outbound: number };
148
+ dialQueue: { pending: number };
149
+ };
150
+ },
151
+ },
135
152
  },
136
153
 
137
154
  access: {
package/src/domain.ts CHANGED
@@ -3,14 +3,6 @@ import { waitFor } from "@peerbit/time";
3
3
 
4
4
  const isNode = typeof process !== "undefined" && process.versions?.node != null;
5
5
 
6
- const validateEmail = (email: any) => {
7
- return String(email)
8
- .toLowerCase()
9
- .match(
10
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
11
- );
12
- };
13
-
14
6
  const getConfigFileTemplate = async (): Promise<string> => {
15
7
  const url = await import("url");
16
8
  const filename = url.fileURLToPath(import.meta.url);
@@ -131,13 +123,9 @@ export const createTestDomain = async () => {
131
123
 
132
124
  export const startCertbot = async (
133
125
  domain: string,
134
- email: string,
135
126
  waitForUp = false,
136
127
  dockerProcessName = "nginx-certbot",
137
128
  ): Promise<void> => {
138
- if (!validateEmail(email)) {
139
- throw new Error("Email for SSL renenewal is invalid");
140
- }
141
129
  const { installDocker, startContainer } = await import("./docker.js");
142
130
 
143
131
  const nginxConfigPath = await getNginxFolderPath();
@@ -153,7 +141,7 @@ export const startCertbot = async (
153
141
  // copy ui from node_modules to home for permission reasons (volume will not work otherwise)
154
142
  const certbotDockerCommand = `cp -r ${uiPath} $(pwd)/ui && docker pull jonasal/nginx-certbot:latest && docker run -d --net=host \
155
143
  --restart unless-stopped \
156
- --env CERTBOT_EMAIL=${email} ${isTest ? "--env STAGING=1" : ""}\
144
+ ${isTest ? "--env STAGING=1" : ""}\
157
145
  -v $(pwd)/nginx_secrets:/etc/letsencrypt \
158
146
  -v ${nginxConfigPath}:/etc/nginx/user_conf.d:ro \
159
147
  -v $(pwd)/ui:/usr/share/nginx/html:ro \
@@ -1,23 +1,5 @@
1
1
  server_names_hash_bucket_size 128;
2
2
 
3
- # --- stream (TCP/UDP) layer ---
4
- stream {
5
- # libp2p TCP forward: /dns4/%DOMAIN%/tcp/4002 -> 127.0.0.1:8001
6
- server {
7
- listen 4002;
8
- proxy_connect_timeout 10s;
9
- proxy_timeout 1h;
10
- proxy_pass 127.0.0.1:8001;
11
- }
12
-
13
- # webrtc-direct UDP forward: /dns4/%DOMAIN%/udp/4004/webrtc-direct -> 127.0.0.1:8004
14
- server {
15
- listen 4003 udp;
16
- proxy_timeout 1h;
17
- proxy_pass 127.0.0.1:8003;
18
- }
19
- }
20
-
21
3
  server {
22
4
  server_name %DOMAIN%;
23
5
  listen [::]:4003 ssl ipv6only=on;
package/src/peerbit.ts CHANGED
@@ -33,16 +33,27 @@ export const create = (properties: {
33
33
  ? [
34
34
  `/dns4/${properties.domain}/tcp/4002`,
35
35
  `/dns4/${properties.domain}/tcp/4003/wss`,
36
- `/dns4/${properties.domain}/tcp/4004/webrtc-direct`,
36
+ `/dns4/${properties.domain}/udp/4004/webrtc-direct`,
37
37
  ]
38
38
  : undefined,
39
- listen: [
40
- `/ip4/127.0.0.1/tcp/${listenPort}`,
41
- `/ip4/127.0.0.1/tcp/${
42
- listenPort !== 0 ? listenPort + 1 : listenPort
43
- }/ws`,
44
- `/ip4/127.0.0.1/udp/${listenPort !== 0 ? listenPort + 2 : listenPort}/webrtc-direct`,
45
- ],
39
+ listen: (() => {
40
+ if (properties.domain) {
41
+ // Direct binds on public ports, keep only local WS for nginx TLS->WS proxy
42
+ return [
43
+ `/ip4/0.0.0.0/tcp/4002`,
44
+ `/ip4/127.0.0.1/tcp/${
45
+ listenPort !== 0 ? listenPort + 1 : listenPort
46
+ }/ws`,
47
+ `/ip4/0.0.0.0/udp/4004/webrtc-direct`,
48
+ ];
49
+ }
50
+ // Local-only defaults (no domain)
51
+ return [
52
+ `/ip4/127.0.0.1/tcp/${listenPort}`,
53
+ `/ip4/127.0.0.1/tcp/${listenPort !== 0 ? listenPort + 1 : listenPort}/ws`,
54
+ `/ip4/127.0.0.1/udp/${listenPort !== 0 ? listenPort + 2 : listenPort}/webrtc-direct`,
55
+ ];
56
+ })(),
46
57
  },
47
58
  connectionMonitor: {
48
59
  abortConnectionOnPingFailure: false,
package/src/routes.ts CHANGED
@@ -14,6 +14,7 @@ export const LOCAL_API_PORT = 8082;
14
14
  export const TRUST_PATH = "/trust";
15
15
  export const PEER_ID_PATH = "/peer/id";
16
16
  export const ADDRESS_PATH = "/peer/address";
17
+ export const STATS_PATH = "/peer/stats";
17
18
  export const PROGRAM_PATH = "/program";
18
19
  export const PROGRAMS_PATH = "/programs";
19
20
  export const PROGRAM_VARIANTS_PATH = "/program/variants";
package/src/server.ts CHANGED
@@ -4,7 +4,6 @@ import { peerIdFromString } from "@libp2p/peer-id";
4
4
  import { fromBase64, getPublicKeyFromPeerId } from "@peerbit/crypto";
5
5
  import {
6
6
  Program,
7
- type ProgramClient,
8
7
  getProgramFromVariant,
9
8
  getProgramFromVariants,
10
9
  } from "@peerbit/program";
@@ -36,6 +35,7 @@ import {
36
35
  PROGRAM_VARIANTS_PATH,
37
36
  RESTART_PATH,
38
37
  SELF_UPDATE_PATH,
38
+ STATS_PATH,
39
39
  STOP_PATH,
40
40
  TRUST_PATH,
41
41
  VERSIONS_PATH,
@@ -268,7 +268,7 @@ function findPeerbitProgramFolder(inputDirectory: string): string | null {
268
268
  }
269
269
 
270
270
  export const startApiServer = async (
271
- client: ProgramClient,
271
+ client: Peerbit,
272
272
  properties: {
273
273
  trust: Trust;
274
274
  session?: Session;
@@ -332,7 +332,7 @@ export const startApiServer = async (
332
332
 
333
333
  const e404 = "404";
334
334
 
335
- const endpoints = (client: ProgramClient): http.RequestListener => {
335
+ const endpoints = (client: Peerbit): http.RequestListener => {
336
336
  return async (req, res) => {
337
337
  res.setHeader("Access-Control-Allow-Origin", "*");
338
338
  res.setHeader("Access-Control-Request-Method", "*");
@@ -887,12 +887,45 @@ export const startApiServer = async (
887
887
  r404();
888
888
  break;
889
889
  }
890
- } */ else if (req.url.startsWith(PEER_ID_PATH)) {
890
+ } */ else if (req.url.startsWith(STATS_PATH)) {
891
+ if (req.method === "GET") {
892
+ try {
893
+ const connections = client.libp2p.getConnections();
894
+ const inbound = connections.filter(
895
+ (c) => c.direction === "inbound",
896
+ ).length;
897
+ const outbound = connections.filter(
898
+ (c) => c.direction === "outbound",
899
+ ).length;
900
+ const dialQueue = client.libp2p.getDialQueue();
901
+
902
+ const payload = {
903
+ connections: {
904
+ total: connections.length,
905
+ inbound,
906
+ outbound,
907
+ },
908
+ dialQueue: {
909
+ pending: dialQueue.length,
910
+ },
911
+ };
912
+ res.setHeader("Content-Type", "application/json");
913
+ res.writeHead(200);
914
+ res.end(JSON.stringify(payload));
915
+ } catch (error: any) {
916
+ res.writeHead(500);
917
+ res.end(error?.message || "Failed to compute stats");
918
+ }
919
+ } else {
920
+ r404();
921
+ }
922
+ } else if (req.url.startsWith(PEER_ID_PATH)) {
891
923
  res.writeHead(200);
892
924
  res.end(client.peerId.toString());
893
925
  } else if (req.url.startsWith(ADDRESS_PATH)) {
894
926
  res.setHeader("Content-Type", "application/json");
895
927
  res.writeHead(200);
928
+
896
929
  const addresses = client.getMultiaddrs().map((x) => x.toString());
897
930
  res.end(JSON.stringify(addresses));
898
931
  } else {