nano-pow 4.1.1 → 4.1.2
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/bin/cli.js +1 -1
- package/dist/bin/server.js +25 -4
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { getRandomValues } from "node:crypto";
|
|
5
5
|
import { createInterface } from "node:readline/promises";
|
|
6
6
|
process.title = "NanoPow CLI";
|
|
7
|
-
process.env.NANO_POW_DEBUG
|
|
7
|
+
delete process.env.NANO_POW_DEBUG;
|
|
8
8
|
process.env.NANO_POW_EFFORT = "";
|
|
9
9
|
process.env.NANO_POW_PORT = "5041";
|
|
10
10
|
function log(...args2) {
|
package/dist/bin/server.js
CHANGED
|
@@ -6,19 +6,40 @@ import { subtle } from "node:crypto";
|
|
|
6
6
|
import { lookup } from "node:dns/promises";
|
|
7
7
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
8
8
|
import * as http from "node:http";
|
|
9
|
-
import { hostname } from "node:os";
|
|
9
|
+
import { homedir, hostname } from "node:os";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
process.title = "NanoPow Server";
|
|
12
12
|
const MAX_REQUEST_SIZE = 1024;
|
|
13
13
|
const MAX_BODY_SIZE = 158;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let DEBUG = !!(process.env.NANO_POW_DEBUG || false);
|
|
15
|
+
let EFFORT = +(process.env.NANO_POW_EFFORT || 8);
|
|
16
|
+
let PORT = +(process.env.NANO_POW_PORT || 5040);
|
|
17
17
|
let browser;
|
|
18
18
|
let page;
|
|
19
19
|
function log(...args) {
|
|
20
20
|
if (DEBUG) console.log(new Date(Date.now()).toLocaleString(), "NanoPow", args);
|
|
21
21
|
}
|
|
22
|
+
async function loadConfig() {
|
|
23
|
+
const contents = await readFile(join(homedir(), ".nano-pow", "config"), "utf-8");
|
|
24
|
+
if (typeof contents === "string") {
|
|
25
|
+
const config = contents.split("\n");
|
|
26
|
+
for (const line of config) {
|
|
27
|
+
const debugMatch = line.match(/^[ \t]*debug[ \t]*(true|false)[ \t]*(#.*)?$/i);
|
|
28
|
+
if (Array.isArray(debugMatch)) {
|
|
29
|
+
DEBUG = !!process.env.NANO_POW_DEBUG || debugMatch?.[1] === "true" || false;
|
|
30
|
+
}
|
|
31
|
+
const effortMatch = line.match(/^[ \t]*effort[ \t]*(\d{1,2})[ \t]*(#.*)?$/i);
|
|
32
|
+
if (Array.isArray(effortMatch)) {
|
|
33
|
+
EFFORT = +(process.env.NANO_POW_EFFORT || effortMatch?.[1] || 8);
|
|
34
|
+
}
|
|
35
|
+
const portMatch = line.match(/^[ \t]*port[ \t]*(\d{1,5})[ \t]*(#.*)?$/i);
|
|
36
|
+
if (Array.isArray(portMatch)) {
|
|
37
|
+
PORT = +(process.env.NANO_POW_PORT || portMatch?.[1] || 5040);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
await loadConfig();
|
|
22
43
|
async function respond(res, data) {
|
|
23
44
|
let statusCode = 500;
|
|
24
45
|
let headers = { "Content-Type": "application/json" };
|