Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1109c77ec2 | ||
|
|
88cf9b37a9 | ||
|
|
2d207f792b | ||
|
|
d67a57861d | ||
|
|
27e9dbfb4e | ||
|
|
a199008fa3 | ||
|
|
e88b786073 | ||
|
|
c03b0a12f8 | ||
|
|
a234041cd1 | ||
|
|
49a779970e | ||
|
|
9545c2594e | ||
|
|
6c23d95feb | ||
|
|
366380395e | ||
|
|
8ea665297f | ||
|
|
f6580c0342 | ||
|
|
34a139040c | ||
|
|
66bea8a42b | ||
|
|
28790fda30 | ||
|
|
0b16af0084 |
@@ -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"]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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.
|
||||
|
||||
17
package.json
17
package.json
@@ -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",
|
||||
|
||||
13
src/main.js
13
src/main.js
@@ -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/");
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user