Compare commits

...

19 Commits

Author SHA1 Message Date
Petr Sloup
1109c77ec2 Update package version to 1.6.0 2017-05-04 12:07:58 +02:00
Petr Sloup
88cf9b37a9 Revert mapbox-gl-native package update
It broke travis (to be further investigated)
2017-05-04 11:21:57 +02:00
Petr Sloup
2d207f792b Update package dependencies 2017-05-04 11:13:24 +02:00
Petr Sloup
d67a57861d Merge pull request #155 from tschaub/reconfigure-on-sighup
Reload configuration on SIGHUP
2017-05-04 11:02:48 +02:00
Petr Sloup
27e9dbfb4e Merge pull request #157 from tschaub/address
Enclose literal IPv6 addresses in brackets
2017-05-04 08:57:17 +02:00
Tim Schaub
a199008fa3 Enclose literal IPv6 addresses in brackets 2017-04-28 07:28:49 -07:00
Tim Schaub
e88b786073 Reload configuration on SIGHUP 2017-04-28 07:13:34 -07:00
Petr Sloup
c03b0a12f8 Merge pull request #156 from tschaub/no-callback
Remove unused callback
2017-04-28 11:04:17 +02:00
Tim Schaub
a234041cd1 Remove unused callback 2017-04-26 08:02:18 -07:00
Petr Sloup
49a779970e Merge pull request #150 from pirxpilot/no-cors
add `--cors` option to allow for optional CORS handling
2017-04-18 09:32:11 +02:00
Petr Sloup
9545c2594e Handle scale in query-based static endpoint 2017-04-14 12:05:03 +02:00
Damian Krzeminski
6c23d95feb add --cors option to allow for optional CORS handling
we are using `cors` middleware with default options which works for most
applications, but does not allow for fine tuning (whitelisting origins
etc.)

this change keeps CORS handling as default to preserve compatibility but
also allows for specying `--no-cors` option which makes it possible to
handle CORS in an independent proxy (NGINX, another node app etc.)
2017-04-12 09:43:43 -07:00
Petr Sloup
366380395e Proper error message when metadata are missing in the mbtiles (close #147) 2017-04-11 19:10:40 +02:00
Petr Sloup
8ea665297f Minor fix in style path handling (allow absolute paths) 2017-04-07 18:53:11 +02:00
Petr Sloup
f6580c0342 Improved request logging 2017-04-04 18:46:18 +02:00
Petr Sloup
34a139040c Slight docker performance optimization 2017-04-04 18:46:18 +02:00
Petr Sloup
66bea8a42b Merge pull request #142 from somthanat/master
Word correction (Forwaded -> Forwarded)
2017-04-03 15:16:40 +02:00
Petr Sloup
28790fda30 Alternative query-based static endpoint 2017-04-03 15:14:40 +02:00
Somthanat Wongsa
0b16af0084 Word correction (Forwaded -> Forwarded) 2017-03-30 20:16:03 +07:00
8 changed files with 100 additions and 33 deletions

View File

@@ -26,5 +26,7 @@ RUN cd /usr/src/app && npm install --production
VOLUME /data
WORKDIR /data
ENV NODE_ENV="production"
EXPOSE 80
ENTRYPOINT ["/usr/src/app/run.sh"]

View File

@@ -8,5 +8,7 @@ RUN cd /usr/src/app && npm install --production
VOLUME /data
WORKDIR /data
ENV NODE_ENV="production"
EXPOSE 80
ENTRYPOINT ["node", "/usr/src/app/", "-p", "80"]

View File

@@ -17,4 +17,4 @@ Nginx can be used to add protection via https, password, referrer, IP address re
Running behind a proxy or a load-balancer
=========================================
If you need to run TileServer GL behind a proxy, make sure the proxy sends ``X-Forwarded-*`` headers to the server (most importantly ``X-Forwarded-Host`` and ``X-Forwaded-Proto``) to ensures the URLs generated inside TileJSON etc. are using the desired domain and protocol.
If you need to run TileServer GL behind a proxy, make sure the proxy sends ``X-Forwarded-*`` headers to the server (most importantly ``X-Forwarded-Host`` and ``X-Forwarded-Proto``) to ensures the URLs generated inside TileJSON etc. are using the desired domain and protocol.

View File

@@ -1,6 +1,6 @@
{
"name": "tileserver-gl",
"version": "1.5.0",
"version": "1.6.0",
"description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
"main": "src/main.js",
"bin": "src/main.js",
@@ -19,16 +19,19 @@
"test": "mocha test/**.js"
},
"dependencies": {
"async": "2.2.0",
"@mapbox/mapbox-gl-native": "3.4.4",
"@mapbox/sphericalmercator": "1.0.5",
"advanced-pool": "0.3.2",
"async": "2.4.0",
"base64url": "2.0.0",
"canvas": "1.6.5",
"clone": "2.1.1",
"color": "1.0.3",
"cors": "2.8.2",
"cors": "2.8.3",
"express": "4.15.2",
"glyph-pbf-composite": "0.0.2",
"handlebars": "4.0.6",
"handlebars": "4.0.8",
"http-shutdown": "^1.2.0",
"mbtiles": "0.9.0",
"morgan": "1.8.1",
"node-pngquant-native": "1.0.4",
@@ -36,11 +39,9 @@
"pbf": "3.0.5",
"proj4": "2.4.3",
"request": "2.81.0",
"sharp": "0.17.2",
"sharp": "0.17.3",
"tileserver-gl-styles": "1.1.1",
"vector-tile": "1.3.0",
"@mapbox/mapbox-gl-native": "3.4.4",
"@mapbox/sphericalmercator": "1.0.5"
"vector-tile": "1.3.0"
},
"devDependencies": {
"should": "^11.2.0",

View File

@@ -32,6 +32,10 @@ var opts = require('nomnom')
default: 8080,
help: 'Port'
})
.option('cors', {
default: true,
help: 'Enable Cross-origin resource sharing headers'
})
.option('verbose', {
abbr: 'V',
flag: true,
@@ -54,7 +58,8 @@ var startServer = function(configPath, config) {
configPath: configPath,
config: config,
bind: opts.bind,
port: opts.port
port: opts.port,
cors: opts.cors
});
};
@@ -70,6 +75,12 @@ var startWithMBTiles = function(mbtilesFile) {
}
var instance = new mbtiles(mbtilesFile, function(err) {
instance.getInfo(function(err, info) {
if (err || !info) {
console.log('ERROR: Metadata missing in the MBTiles.');
console.log(' Make sure ' + path.basename(mbtilesFile) +
' is valid MBTiles.');
process.exit(1);
}
var bounds = info.bounds;
var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");

View File

@@ -166,7 +166,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
});
};
var styleJSONPath = path.join(options.paths.styles, styleFile);
var styleJSONPath = path.resolve(options.paths.styles, styleFile);
styleJSON = clone(require(styleJSONPath));
var httpTester = /^(http(s)?:)?\/\//;
@@ -564,14 +564,11 @@ module.exports = function(options, repo, params, id, dataResolver) {
res, next, overlay);
});
var boundsPattern =
util.format(':minx(%s),:miny(%s),:maxx(%s),:maxy(%s)',
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN);
app.get(util.format(staticPattern, boundsPattern), function(req, res, next) {
var serveBounds = function(req, res, next) {
var raw = req.params.raw;
var bbox = [+req.params.minx, +req.params.miny,
+req.params.maxx, +req.params.maxy];
var center = [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2];
var transformer = raw ?
mercator.inverse.bind(mercator) : dataProjWGStoInternalWGS;
@@ -583,6 +580,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
bbox[1] = minCorner[1];
bbox[2] = maxCorner[0];
bbox[3] = maxCorner[1];
center = transformer(center);
}
var w = req.params.width | 0,
@@ -591,8 +589,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
format = req.params.format;
var z = calcZForBBox(bbox, w, h, req.query),
x = (bbox[0] + bbox[2]) / 2,
y = (bbox[1] + bbox[3]) / 2,
x = center[0],
y = center[1],
bearing = 0,
pitch = 0;
@@ -601,6 +599,34 @@ module.exports = function(options, repo, params, id, dataResolver) {
path, req.query);
return respondImage(z, x, y, bearing, pitch, w, h, scale, format,
res, next, overlay);
};
var boundsPattern =
util.format(':minx(%s),:miny(%s),:maxx(%s),:maxy(%s)',
FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN, FLOAT_PATTERN);
app.get(util.format(staticPattern, boundsPattern), serveBounds);
app.get('/static/', function(req, res, next) {
for (var key in req.query) {
req.query[key.toLowerCase()] = req.query[key];
}
req.params.raw = true;
req.params.format = (req.query.format || 'image/png').split('/').pop();
var bbox = (req.query.bbox || '').split(',');
req.params.minx = bbox[0];
req.params.miny = bbox[1];
req.params.maxx = bbox[2];
req.params.maxy = bbox[3];
req.params.width = req.query.width || '256';
req.params.height = req.query.height || '256';
if (req.query.scale) {
req.params.width /= req.query.scale;
req.params.height /= req.query.scale;
req.params.scale = '@' + req.query.scale;
}
return serveBounds(req, res, next);
});
var autoPattern = 'auto';

View File

@@ -10,7 +10,7 @@ var clone = require('clone'),
module.exports = function(options, repo, params, id, reportTiles, reportFont) {
var app = express().disable('x-powered-by');
var styleFile = path.join(options.paths.styles, params.style);
var styleFile = path.resolve(options.paths.styles, params.style);
var styleJSON = clone(require(styleFile));
Object.keys(styleJSON.sources).forEach(function(name) {

View File

@@ -10,6 +10,7 @@ var fs = require('fs'),
var base64url = require('base64url'),
clone = require('clone'),
cors = require('cors'),
enableShutdown = require('http-shutdown'),
express = require('express'),
handlebars = require('handlebars'),
mercator = new (require('@mapbox/sphericalmercator'))(),
@@ -28,7 +29,7 @@ if (!isLight) {
serve_rendered = require('./serve_rendered');
}
module.exports = function(opts, callback) {
function start(opts) {
console.log('Starting server');
var app = express().disable('x-powered-by'),
@@ -41,10 +42,9 @@ module.exports = function(opts, callback) {
app.enable('trust proxy');
callback = callback || function() {};
if (process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test') {
if (process.env.NODE_ENV == 'production') {
app.use(morgan('tiny'));
} else if (process.env.NODE_ENV !== 'test') {
app.use(morgan('dev'));
}
@@ -89,7 +89,9 @@ module.exports = function(opts, callback) {
var data = clone(config.data || {});
app.use(cors());
if (opts.cors) {
app.use(cors());
}
Object.keys(config.styles || {}).forEach(function(id) {
var item = config.styles[id];
@@ -354,19 +356,42 @@ module.exports = function(opts, callback) {
});
var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function() {
console.log('Listening at http://%s:%d/',
this.address().address, this.address().port);
return callback();
var address = this.address().address;
if (address.indexOf('::') === 0) {
address = '[' + address + ']'; // literal IPv6 address
}
console.log('Listening at http://%s:%d/', address, this.address().port);
});
process.on('SIGINT', function() {
process.exit();
});
// add server.shutdown() to gracefully stop serving
enableShutdown(server);
setTimeout(callback, 1000);
return {
app: app,
server: server
};
}
module.exports = function(opts) {
var running = start(opts);
process.on('SIGINT', function() {
process.exit();
});
process.on('SIGHUP', function() {
console.log('Stopping server and reloading config');
running.server.shutdown(function() {
for (var key in require.cache) {
delete require.cache[key];
}
var restarted = start(opts);
running.server = restarted.server;
running.app = restarted.app;
});
});
return running;
};