@peerbit/server 5.1.16 → 5.2.1
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.
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +17 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/client.d.ts +8 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +17 -1
- package/dist/src/client.js.map +1 -1
- package/dist/src/routes.d.ts +1 -0
- package/dist/src/routes.d.ts.map +1 -1
- package/dist/src/routes.js +1 -0
- package/dist/src/routes.js.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +35 -1
- package/dist/src/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui/assets/index-DfjdQIsv.js +66 -0
- package/dist/ui/index.html +1 -1
- package/package.json +3 -3
- package/src/cli.ts +17 -0
- package/src/client.ts +19 -0
- package/src/routes.ts +1 -0
- package/src/server.ts +38 -0
- package/dist/ui/assets/index-_95xTF45.js +0 -66
package/dist/ui/index.html
CHANGED
|
@@ -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-
|
|
26
|
+
<script type="module" crossorigin src="/assets/index-DfjdQIsv.js"></script>
|
|
27
27
|
<link rel="stylesheet" crossorigin href="/assets/index-CIfVvUo9.css">
|
|
28
28
|
</head>
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/server",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"author": "dao.xyz",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@peerbit/test-lib": "^0.0.1",
|
|
70
|
-
"@peerbit/test-utils": "2.1.
|
|
70
|
+
"@peerbit/test-utils": "2.1.40",
|
|
71
71
|
"@types/yargs": "17.0.24",
|
|
72
72
|
"aws-sdk": "^2.1259.0",
|
|
73
73
|
"dotenv": "^16.1.4",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"axios": "^1.4.0",
|
|
80
80
|
"chalk": "^5.3.0",
|
|
81
|
-
"peerbit": "4.1.
|
|
81
|
+
"peerbit": "4.1.30",
|
|
82
82
|
"yargs": "^17.7.2",
|
|
83
83
|
"tar-stream": "^3.1.7",
|
|
84
84
|
"tmp": "^0.2.1",
|
package/src/cli.ts
CHANGED
|
@@ -1129,6 +1129,23 @@ export const cli = async (args?: string[]) => {
|
|
|
1129
1129
|
}
|
|
1130
1130
|
},
|
|
1131
1131
|
})
|
|
1132
|
+
.command({
|
|
1133
|
+
command: "log",
|
|
1134
|
+
describe: "Fetch log file contents from the server",
|
|
1135
|
+
builder: (yargs) => {
|
|
1136
|
+
yargs.option("n", {
|
|
1137
|
+
alias: "lines",
|
|
1138
|
+
type: "number",
|
|
1139
|
+
describe: "Number of last lines to display",
|
|
1140
|
+
});
|
|
1141
|
+
return yargs;
|
|
1142
|
+
},
|
|
1143
|
+
handler: async (args) => {
|
|
1144
|
+
for (const api of apis) {
|
|
1145
|
+
api.log(await api.api.log.fetch(args.n));
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
})
|
|
1132
1149
|
.help()
|
|
1133
1150
|
.strict()
|
|
1134
1151
|
.scriptName("")
|
package/src/client.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
BOOTSTRAP_PATH,
|
|
16
16
|
INSTALL_PATH,
|
|
17
17
|
LOCAL_API_PORT,
|
|
18
|
+
LOG_PATH, // <-- Added the log route constant
|
|
18
19
|
PEER_ID_PATH,
|
|
19
20
|
PROGRAMS_PATH,
|
|
20
21
|
PROGRAM_PATH,
|
|
@@ -258,6 +259,24 @@ export const createClient = async (
|
|
|
258
259
|
}),
|
|
259
260
|
);
|
|
260
261
|
},
|
|
262
|
+
log: {
|
|
263
|
+
/**
|
|
264
|
+
* Fetches the log from the server.
|
|
265
|
+
* @param n Optional number of last lines to return.
|
|
266
|
+
* @returns The log content as a string.
|
|
267
|
+
*/
|
|
268
|
+
fetch: async (n?: number): Promise<string> => {
|
|
269
|
+
// Build the URL to the log endpoint, adding the query parameter if n is provided.
|
|
270
|
+
const url = endpoint + LOG_PATH + (n !== undefined ? `?n=${n}` : "");
|
|
271
|
+
const resp = throwIfNot200(
|
|
272
|
+
await axiosInstance.get(url, {
|
|
273
|
+
validateStatus,
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
return resp.data as string;
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
|
|
261
280
|
terminate: async () => {
|
|
262
281
|
const { terminateNode } = await import("./aws.js");
|
|
263
282
|
if (remote.origin?.type === "aws") {
|
package/src/routes.ts
CHANGED
package/src/server.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
BOOTSTRAP_PATH,
|
|
30
30
|
INSTALL_PATH,
|
|
31
31
|
LOCAL_API_PORT,
|
|
32
|
+
LOG_PATH,
|
|
32
33
|
PEER_ID_PATH,
|
|
33
34
|
PROGRAMS_PATH,
|
|
34
35
|
PROGRAM_PATH,
|
|
@@ -609,6 +610,43 @@ export const startApiServer = async (
|
|
|
609
610
|
r404();
|
|
610
611
|
break;
|
|
611
612
|
}
|
|
613
|
+
} else if (req.url.startsWith(LOG_PATH)) {
|
|
614
|
+
if (req.method === "GET") {
|
|
615
|
+
try {
|
|
616
|
+
// Use the URL API to parse query parameters.
|
|
617
|
+
const urlObj = new URL(req.url, `http://localhost:${port}`);
|
|
618
|
+
const nLinesParam = urlObj.searchParams.get("n");
|
|
619
|
+
|
|
620
|
+
// Define the path to your log file. Adjust the path if log.txt is elsewhere.
|
|
621
|
+
const logFilePath = path.join(process.cwd(), "log.txt");
|
|
622
|
+
|
|
623
|
+
// Check that the file exists.
|
|
624
|
+
if (!fs.existsSync(logFilePath)) {
|
|
625
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
626
|
+
res.end("Log file not found.");
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// Read the log file content.
|
|
631
|
+
let logContent = fs.readFileSync(logFilePath, "utf8");
|
|
632
|
+
|
|
633
|
+
// If the query parameter 'n' is provided, return only that many last lines.
|
|
634
|
+
if (nLinesParam) {
|
|
635
|
+
const n = parseInt(nLinesParam, 10);
|
|
636
|
+
if (!isNaN(n) && n > 0) {
|
|
637
|
+
const lines = logContent.split("\n");
|
|
638
|
+
logContent = lines.slice(-n).join("\n");
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
643
|
+
res.end(logContent);
|
|
644
|
+
} catch (error: any) {
|
|
645
|
+
console.error("Error fetching log file:", error);
|
|
646
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
647
|
+
res.end("Error reading log: " + error.message);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
612
650
|
} else if (req.url.startsWith(STOP_PATH)) {
|
|
613
651
|
switch (req.method) {
|
|
614
652
|
case "POST":
|