tileblaster 1.0.0 → 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/config.dist.js +1 -1
- package/lib/config.js +110 -0
- package/package.json +3 -3
- package/readme.md +2 -2
- package/tileblaster.js +39 -15
package/config.dist.js
CHANGED
|
@@ -3,7 +3,7 @@ const config = module.exports = {
|
|
|
3
3
|
|
|
4
4
|
id: "tileblaster", // id of the tileblaster instance, in case you want to run more than one; default: tileblaster
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
threads: 1, // number of worker threads in cluster, default: 1
|
|
7
7
|
queue: 10, // number of parallel tile processes per worker, default: 12
|
|
8
8
|
|
|
9
9
|
server: {
|
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
|
},
|
package/readme.md
CHANGED
|
@@ -70,8 +70,8 @@ server {
|
|
|
70
70
|
proxy_set_header Accept-Encoding $http_accept_encoding;
|
|
71
71
|
proxy_set_header Accept-Language $http_accept_language;
|
|
72
72
|
proxy_set_header Accept $http_accept;
|
|
73
|
-
proxy_set_header If-Modified-Since $http_if_modified_since
|
|
74
|
-
proxy_set_header If-None-Match $http_if_none_match
|
|
73
|
+
proxy_set_header If-Modified-Since $http_if_modified_since;
|
|
74
|
+
proxy_set_header If-None-Match $http_if_none_match;
|
|
75
75
|
proxy_http_version 1.1;
|
|
76
76
|
proxy_pass http://tileblaster;
|
|
77
77
|
}
|
package/tileblaster.js
CHANGED
|
@@ -177,10 +177,15 @@ tileblaster.prototype.shutdown = function(){
|
|
|
177
177
|
let closed = 0;
|
|
178
178
|
self.servers.forEach(function(server){
|
|
179
179
|
server.close(function(){
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
180
|
+
(function(fn){
|
|
181
|
+
if (!server.socket) return fn();
|
|
182
|
+
fs.unlink(server.socket, fn);
|
|
183
|
+
})(function(){
|
|
184
|
+
if (++closed === self.servers.length) {
|
|
185
|
+
debug.info("All Servers Closed");
|
|
186
|
+
process.exit(0);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
184
189
|
});
|
|
185
190
|
});
|
|
186
191
|
// watchdog
|
|
@@ -422,19 +427,38 @@ tileblaster.prototype.listen = function(router){
|
|
|
422
427
|
|
|
423
428
|
} else if (listen.socket) {
|
|
424
429
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
430
|
+
// create different sockets per instance
|
|
431
|
+
if (self.config.threads > 1) {
|
|
432
|
+
let ext = path.extname(listen.socket);
|
|
433
|
+
listen.socket = path.join(path.dirname(listen.socket), path.basename(listen.socket, ext) + self.config.id + ext);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ensure socket dir exists
|
|
437
|
+
fs.mkdir(path.dirname(listen.socket), { recursive: true }, function(err){
|
|
438
|
+
if (err && err.code !== "ENOENT") return debug.error("Creating socket dir '%s':", path.dirname(listen.socket), err);
|
|
439
|
+
|
|
440
|
+
// inlink old socket
|
|
441
|
+
fs.unlink(listen.socket, function(err) { // try unlink leftover socket
|
|
442
|
+
if (err && err.code !== "ENOENT") return debug.error("Deleting socket '%s':", listen.socket, err);
|
|
443
|
+
|
|
444
|
+
server.listen(listen.socket, function(err) {
|
|
445
|
+
if (err) return debug.error("Binding to socket '%s':", listen.socket, err);
|
|
446
|
+
|
|
447
|
+
// store socket path
|
|
448
|
+
server.socket = listen.socket;
|
|
449
|
+
|
|
450
|
+
debug.info("Listening on socket '%s'", listen.socket);
|
|
451
|
+
self.servers.push(server);
|
|
452
|
+
if (listen.mode) fs.chmod(listen.socket, listen.mode, function(err){
|
|
453
|
+
if (err) return debug.error("Changing permissions of socket '%s' to '%s':", listen.socket, listen.perms.toString(8), err);
|
|
454
|
+
});
|
|
455
|
+
if (listen.group) fs.chown(listen.socket, os.userInfo().uid, listen.group, function(err){
|
|
456
|
+
if (err) return debug.error("Changing gid of socket '%s' to '%s':", listen.socket, listen.gid, err);
|
|
457
|
+
});
|
|
458
|
+
|
|
436
459
|
});
|
|
437
460
|
});
|
|
461
|
+
|
|
438
462
|
});
|
|
439
463
|
|
|
440
464
|
}
|