tileblaster 1.0.4 → 1.0.6

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/cache.js CHANGED
@@ -14,7 +14,7 @@ module.exports = function({ opts, data, res }, next, skip){
14
14
  if (!cache.hasOwnProperty(data.map)) {
15
15
 
16
16
  // store instance
17
- cache.store = this.lib.store({ root: config.paths.data, ext: config.id+".tmp" });
17
+ cache.store = this.lib.store({ root: config.paths.data, ext: "."+config.id+".tmp" });
18
18
 
19
19
  // merge opts of all uses of the cache builtin in a map config
20
20
  opts = config.maps[data.map].filter(function(use){
package/builtins/check.js CHANGED
@@ -2,13 +2,26 @@
2
2
 
3
3
  const cache = {};
4
4
 
5
- module.exports = function({ req, res, opts, data }, next){
5
+ module.exports = function({ req, res, opts, data }, next, skip){
6
6
 
7
7
  // fill cache for map
8
8
  if (!cache.hasOwnProperty(data.map)) {
9
9
 
10
10
  cache[data.map] = {};
11
11
 
12
+ // skip function
13
+ cache[data.map].abort = function(err){
14
+ res.statusCode = cache[data.map].status;
15
+ if (cache[data.map].hints && err) res.setHeader("x-tileblaster-hint", err.message || err.toString());
16
+ res.end();
17
+ res.used = true; // mark connection as used
18
+ return skip(); // skip rest of jobs
19
+ };
20
+
21
+ cache[data.map].status = (opts.status && Number.isInteger(opts.status)) ? opts.status : 204;
22
+
23
+ cache[data.map].hints = !!opts.hints;
24
+
12
25
  // assume reasonable default if no zoom level was specified
13
26
  cache[data.map].zoom = (!opts.zoom || opts.zoom.length === 0) ? [ 0, 24 ] : opts.zoom;
14
27
 
@@ -86,28 +99,28 @@ module.exports = function({ req, res, opts, data }, next){
86
99
  opts = cache[data.map];
87
100
 
88
101
  // check for NaNs
89
- if (isNaN(data.req.params.z) || isNaN(data.req.params.x) || isNaN(data.req.params.y)) return next(new Error("illegal zxy."));
102
+ if (isNaN(data.req.params.z) || isNaN(data.req.params.x) || isNaN(data.req.params.y)) return cache[data.map].abort(new Error("illegal zxy."));
90
103
 
91
104
  // check zoom
92
- if (data.req.params.z < opts.minZoom || data.req.params.z > opts.maxZoom) return next(new Error("illegal zoom."));
105
+ if (data.req.params.z < opts.minZoom || data.req.params.z > opts.maxZoom) return cache[data.map].abort(new Error("illegal zoom."));
93
106
 
94
107
  // check bounds
95
108
  if (opts.bounds) {
96
109
  if (opts.bounds[data.req.params.z][0] < opts.bounds[data.req.params.z][2]) { // check for bounds spanning antimeridian
97
110
  // bounds don't span antimeridian
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."));
111
+ if (data.req.params.x < opts.bounds[data.req.params.z][0] || data.req.params.x > opts.bounds[data.req.params.z][2]) return cache[data.map].abort(new Error("x is out of bounds."));
99
112
  } else {
100
113
  // 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"));
114
+ if (data.req.params.x > opts.bounds[data.req.params.z][0] && data.req.params.x < opts.bounds[data.req.params.z][2]) return cache[data.map].abort(new Error("x is out of bounds, bounds span antimeridian"));
102
115
  }
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."));
116
+ if (data.req.params.y < opts.bounds[data.req.params.z][1] || data.req.params.y > opts.bounds[data.req.params.z][3]) return cache[data.map].abort(new Error("y is out of bounds."));
104
117
  }
105
118
 
106
119
  // check 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."));
120
+ if (opts.extensions.length > 0 && !opts.extensions.includes(data.req.params.e) && !opts.extensions.includes(data.req.params.f)) return cache[data.map].abort(new Error("illegal extension."));
108
121
 
109
122
  // check density
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."));
123
+ if (opts.density && !opts.density.includes(data.req.params.d) && !opts.density.includes(data.req.params.f)) return cache[data.map].abort(new Error("illegal density marker."));
111
124
 
112
125
  // all passed
113
126
  next();
@@ -44,6 +44,7 @@ module.exports = function({ req, res, opts, data }, next){
44
44
  };
45
45
  data.tiles.push({
46
46
  ...tile,
47
+ path: tile.path+".br",
47
48
  buffer: compressed,
48
49
  compression: "br",
49
50
  headers: { ...(tile.headers||{}), "content-encoding": "br" },
@@ -64,6 +65,7 @@ module.exports = function({ req, res, opts, data }, next){
64
65
  }
65
66
  data.tiles.push({
66
67
  ...tile,
68
+ path: tile.path+".gz",
67
69
  buffer: compressed,
68
70
  compression: "gzip",
69
71
  headers: { ...(tile.headers||{}), "content-encoding": "gzip" },
package/config.dist.js CHANGED
@@ -68,7 +68,9 @@ const config = module.exports = {
68
68
  density: [ "", "@2x", "@3x" ], // allowed density markeers
69
69
  check: function(params, fn) { // override check function, params from parse
70
70
  fn(new Error("Check failed")); // deliver error if check failed
71
- }
71
+ },
72
+ status: 204,
73
+ hints: true,
72
74
  },{ // get from cache, skip to `skipto` if successful
73
75
  builtin: "cache",
74
76
  skipto: "deliver",
package/docs/config.md CHANGED
@@ -151,7 +151,9 @@ within a bounding box, to specific extensions and densities, or use your own che
151
151
  density: [ "", "@2x", "@3x" ], // allowed density markeers
152
152
  check: function(params, fn) { // override check function, params from parse
153
153
  fn(new Error("Check failed")); // deliver error if check failed
154
- }
154
+ },
155
+ status: 204, // http status code delivered on fail; default: 204
156
+ hints: false, // send `x-tileblaster-hint` header with error message
155
157
  }
156
158
  ```
157
159
 
package/docs/todo.md CHANGED
@@ -70,9 +70,9 @@
70
70
  * [ ] Map Web Interface, Configurable
71
71
  * [ ] Configurable Index Page
72
72
  * [ ] Support for Glyphs and Styles, tile.json proxy
73
- * [ ] Better Error Handling
74
- * [ ] Error wrapper (to pass along http status etc)?
75
- * [ ] 404 for nonexistant tiles
73
+ * [x] Better Error Handling
74
+ * [x] Error wrapper (to pass along http status etc)?
75
+ * [x] Skip for nonexistant tiles
76
76
  * [ ] Render Vector Tiles with MapLibreGL-Native
77
77
  * [ ] Improve Debug Consistency
78
78
  * [ ] Documentation: How to write a plugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tileblaster",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "a quick and versatile map tile caching proxy",
5
5
  "main": "tileblaster.js",
6
6
  "bin": {