tileblaster 1.0.1 → 1.0.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/lib/config.js +110 -0
- package/package.json +3 -3
package/lib/config.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// parse argv and load config
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const format = require("node:util").format;
|
|
6
|
+
const package = require("../package.json");
|
|
7
|
+
const minimist = require("minimist");
|
|
8
|
+
|
|
9
|
+
// parse command line arguments
|
|
10
|
+
const argv = minimist(process.argv.slice(2), {
|
|
11
|
+
alias: { v: "verbose", h: "help", s: "socket", p: "port", c: "config", t: "threads" },
|
|
12
|
+
boolean: [ "help", "verbose" ],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function usage(err){
|
|
16
|
+
if (err) console.error("%s: %s", package.name, err);
|
|
17
|
+
else console.error("%s %s -- %s", package.name, package.version, package.description);
|
|
18
|
+
console.error("");
|
|
19
|
+
console.error("Usage: %s [options] [-c] config.js", package.name);
|
|
20
|
+
console.error("Options:");
|
|
21
|
+
console.error(" -c --config <config.js> load config file");
|
|
22
|
+
console.error(" -p --port <[host:]port> listen on this port (overrides config)");
|
|
23
|
+
console.error(" -s --socket <socket[,mode,gid]> listen on this socket (overrides config)");
|
|
24
|
+
console.error(" -t --threads <num> number of threads (overrides config)");
|
|
25
|
+
console.error(" -h --help print help screen");
|
|
26
|
+
console.error(" -v --verbose enable debug output");
|
|
27
|
+
console.error(" -q --quiet disable debug output");
|
|
28
|
+
console.error("");
|
|
29
|
+
process.exit(err?1:0);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// show help
|
|
33
|
+
if (argv.h) usage();
|
|
34
|
+
|
|
35
|
+
// enable/disable debug output when --verbose or --quiet
|
|
36
|
+
if (argv.v) process.env.DEBUG = process.env.DEBUG || "tileblaster";
|
|
37
|
+
if (argv.q) process.env.DEBUG = undefined;
|
|
38
|
+
|
|
39
|
+
// if no --config, try last argument
|
|
40
|
+
if (!argv.c && argv._.length > 0) argv.c = argv._.pop();
|
|
41
|
+
if (!argv.c) usage("No config file specified.");
|
|
42
|
+
|
|
43
|
+
// resolve config path
|
|
44
|
+
const configfile = path.resolve(process.cwd(), argv.c);
|
|
45
|
+
if (!fs.existsSync(configfile)) usage(format("No config file '%s' does not exist.", configfile));
|
|
46
|
+
|
|
47
|
+
// load config
|
|
48
|
+
const config = (function(){
|
|
49
|
+
try {
|
|
50
|
+
return require(configfile);
|
|
51
|
+
} catch(err) {
|
|
52
|
+
usage(format("Could not load config file: %s", err.toString()));
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
|
|
56
|
+
// expose configfile for watching
|
|
57
|
+
config._file = configfile;
|
|
58
|
+
|
|
59
|
+
// override threads
|
|
60
|
+
if (argv.t) {
|
|
61
|
+
let threads = parseInt(argv.t,10);
|
|
62
|
+
if (isNaN(threads) || !isFinite(threads)) return usage(format("Illegal number of threads: %s", argv.t));
|
|
63
|
+
config.threads = threads;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// override host and port
|
|
67
|
+
if (argv.p) {
|
|
68
|
+
let host, port;
|
|
69
|
+
if (typeof argv.p === "string" && argv.p.includes(":")) {
|
|
70
|
+
host = argv.p.split(":");
|
|
71
|
+
port = parseInt(host.pop());
|
|
72
|
+
host = host.pop().toLowerCase();
|
|
73
|
+
} else {
|
|
74
|
+
port = parseInt(argv.p,10);
|
|
75
|
+
host = "localhost";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// check
|
|
79
|
+
if (isNaN(port) || !isFinite(port) || port < 1 || port > 65535) return usage(format("Illegal port: %s", argv.p));
|
|
80
|
+
if (!/^[a-z0-9\-\.\_]$/i.test(host)) return usage(format("Illegal hostname: %s", argv.p));
|
|
81
|
+
|
|
82
|
+
// remove all listen directives with port
|
|
83
|
+
config.listen = config.listen.filter(function(l){
|
|
84
|
+
return !l.hasOwnProperty("port");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// add our own
|
|
88
|
+
config.listen.push({ port, host });
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// override socket
|
|
92
|
+
if (argv.s) {
|
|
93
|
+
let socket, mode, group;
|
|
94
|
+
socket = socket.split(/,/g);
|
|
95
|
+
group = (socket.length >= 3) ? socket[2] : false;
|
|
96
|
+
mode = (socket.length >= 2) ? parseInt(socket[1],8) : 0o660;
|
|
97
|
+
socket = socket[0];
|
|
98
|
+
|
|
99
|
+
// remove all listen directives with port
|
|
100
|
+
config.listen = config.listen.filter(function(l){
|
|
101
|
+
return !l.hasOwnProperty("socket");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// add our own
|
|
105
|
+
config.listen.push({ socket, mode, group });
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// export
|
|
110
|
+
module.exports = config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tileblaster",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "a quick and versatile map tile caching proxy",
|
|
5
5
|
"main": "tileblaster.js",
|
|
6
6
|
"bin": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"mbg": "^0.0.2",
|
|
36
36
|
"node-liblzma": "^1.1.9",
|
|
37
37
|
"optipng-js": "^0.1.2",
|
|
38
|
-
"pmtiles": "^2.
|
|
39
|
-
"sharp": "^0.32.
|
|
38
|
+
"pmtiles": "^2.9.0",
|
|
39
|
+
"sharp": "^0.32.4",
|
|
40
40
|
"versatiles": "^0.3.1",
|
|
41
41
|
"vtt": "^0.0.3"
|
|
42
42
|
},
|