tileblaster 1.0.1 → 1.0.3

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/builtins/check.js CHANGED
@@ -1,4 +1,4 @@
1
- // check data.params against constraints
1
+ // check data.req.params against constraints
2
2
 
3
3
  const cache = {};
4
4
 
@@ -86,28 +86,28 @@ module.exports = function({ req, res, opts, data }, next){
86
86
  opts = cache[data.map];
87
87
 
88
88
  // check for NaNs
89
- if (isNaN(data.params.z) || isNaN(data.params.x) || isNaN(data.params.y)) return next(new Error("illegal zxy."));
89
+ if (isNaN(data.req.params.z) || isNaN(data.req.params.x) || isNaN(data.req.params.y)) return next(new Error("illegal zxy."));
90
90
 
91
91
  // check zoom
92
- if (data.params.z < opts.minZoom || data.params.z > opts.maxZoom) return next(new Error("illegal zoom."));
92
+ if (data.req.params.z < opts.minZoom || data.req.params.z > opts.maxZoom) return next(new Error("illegal zoom."));
93
93
 
94
94
  // check bounds
95
95
  if (opts.bounds) {
96
- if (opts.bounds[data.params.z][0] < opts.bounds[data.params.z][2]) { // check for bounds spanning antimeridian
96
+ if (opts.bounds[data.req.params.z][0] < opts.bounds[data.req.params.z][2]) { // check for bounds spanning antimeridian
97
97
  // bounds don't span antimeridian
98
- if (data.params.x < opts.bounds[data.params.z][0] || data.params.x > opts.bounds[data.params.z][2]) return next(new Error("x is out of bounds."));
98
+ if (data.req.params.x < opts.bounds[data.req.params.z][0] || data.req.params.x > opts.bounds[data.req.params.z][2]) return next(new Error("x is out of bounds."));
99
99
  } else {
100
100
  // bounds span antimeridian
101
- if (data.params.x > opts.bounds[data.params.z][0] && data.params.x < opts.bounds[data.params.z][2]) return next(new Error("x is out of bounds, bounds span antimeridian"));
101
+ if (data.req.params.x > opts.bounds[data.req.params.z][0] && data.req.params.x < opts.bounds[data.req.params.z][2]) return next(new Error("x is out of bounds, bounds span antimeridian"));
102
102
  }
103
- if (data.params.y < opts.bounds[data.params.z][1] || data.params.y > opts.bounds[data.params.z][3]) return next(new Error("y is out of bounds."));
103
+ if (data.req.params.y < opts.bounds[data.req.params.z][1] || data.req.params.y > opts.bounds[data.req.params.z][3]) return next(new Error("y is out of bounds."));
104
104
  }
105
105
 
106
106
  // check extension
107
- if (opts.extensions.length > 0 && !opts.extensions.includes(data.params.e) && !opts.extensions.includes(data.params.f)) return next(new Error("illegal extension."));
107
+ if (opts.extensions.length > 0 && !opts.extensions.includes(data.req.params.e) && !opts.extensions.includes(data.req.params.f)) return next(new Error("illegal extension."));
108
108
 
109
109
  // check density
110
- if (opts.density && !opts.density.includes(data.params.d) && !opts.density.includes(data.params.f)) return next(new Error("illegal density marker."));
110
+ if (opts.density && !opts.density.includes(data.req.params.d) && !opts.density.includes(data.req.params.f)) return next(new Error("illegal density marker."));
111
111
 
112
112
  // all passed
113
113
  next();
@@ -80,7 +80,7 @@ module.exports = function({ req, res, opts, data }, next){
80
80
  }, [])).then(function(){
81
81
 
82
82
  // set tile to best compressed tile client accepts FIXME find by buffer size?
83
- const bestCompression = (opts.brotli && data.capabilities.br) ? "br" : (opts.gzip && data.capabilities.gz) ? "gzip" : null;
83
+ const bestCompression = (opts.brotli && data.req.supports.br) ? "br" : (opts.gzip && data.req.supports.gz) ? "gzip" : null;
84
84
  if (bestCompression) data.tile = data.tiles.find(function(tile){
85
85
  return tile.compression === bestCompression && tile.mimetype === data.tile.mimetype && tile.filetype === data.tile.filetype;
86
86
  }) || data.tile;
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.1",
3
+ "version": "1.0.3",
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.7.1",
39
- "sharp": "^0.32.0",
38
+ "pmtiles": "^2.9.0",
39
+ "sharp": "^0.32.4",
40
40
  "versatiles": "^0.3.1",
41
41
  "vtt": "^0.0.3"
42
42
  },