add public_url option
This commit is contained in:
+11
-1
@@ -36,6 +36,11 @@ var opts = require('nomnom')
|
||||
default: true,
|
||||
help: 'Enable Cross-origin resource sharing headers'
|
||||
})
|
||||
.option('public_url', {
|
||||
abbr: 'u',
|
||||
default: '',
|
||||
help: 'Enable exposing the server on subpaths, not necessarily the root of the domain'
|
||||
})
|
||||
.option('verbose', {
|
||||
abbr: 'V',
|
||||
flag: true,
|
||||
@@ -54,12 +59,17 @@ var opts = require('nomnom')
|
||||
console.log('Starting ' + packageJson.name + ' v' + packageJson.version);
|
||||
|
||||
var startServer = function(configPath, config) {
|
||||
var publicUrl = opts.public_url;
|
||||
if (publicUrl && publicUrl.lastIndexOf('/') !== publicUrl.length - 1) {
|
||||
publicUrl += '/';
|
||||
}
|
||||
return require('./server')({
|
||||
configPath: configPath,
|
||||
config: config,
|
||||
bind: opts.bind,
|
||||
port: opts.port,
|
||||
cors: opts.cors
|
||||
cors: opts.cors,
|
||||
publicUrl: publicUrl
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+3
-2
@@ -6,8 +6,9 @@ var path = require('path'),
|
||||
var clone = require('clone'),
|
||||
express = require('express');
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
module.exports = function(options, repo, params, id, publicUrl, reportTiles, reportFont) {
|
||||
var app = express().disable('x-powered-by');
|
||||
|
||||
var styleFile = path.resolve(options.paths.styles, params.style);
|
||||
@@ -79,7 +80,7 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||
query = '?' + queryParams.join('&');
|
||||
}
|
||||
return url.replace(
|
||||
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
||||
'local://', utils.getPublicUrl(publicUrl, req)) + query;
|
||||
};
|
||||
|
||||
var styleJSON_ = clone(styleJSON);
|
||||
|
||||
+7
-6
@@ -109,7 +109,7 @@ function start(opts) {
|
||||
}
|
||||
|
||||
if (item.serve_data !== false) {
|
||||
startupPromises.push(serve_style(options, serving.styles, item, id,
|
||||
startupPromises.push(serve_style(options, serving.styles, item, id, opts.publicUrl,
|
||||
function(mbtiles, fromData) {
|
||||
var dataItemId;
|
||||
Object.keys(data).forEach(function(id) {
|
||||
@@ -194,7 +194,7 @@ function start(opts) {
|
||||
version: styleJSON.version,
|
||||
name: styleJSON.name,
|
||||
id: id,
|
||||
url: req.protocol + '://' + req.headers.host +
|
||||
url: utils.getPublicUrl(opts.publicUrl, req) +
|
||||
'/styles/' + id + '/style.json' + query
|
||||
});
|
||||
});
|
||||
@@ -260,6 +260,7 @@ function start(opts) {
|
||||
}
|
||||
}
|
||||
data['server_version'] = packageJson.name + ' v' + packageJson.version;
|
||||
data['public_url'] = opts.publicUrl || '/';
|
||||
data['is_light'] = isLight;
|
||||
data['key_query_part'] =
|
||||
req.query.key ? 'key=' + req.query.key + '&' : '';
|
||||
@@ -293,8 +294,8 @@ function start(opts) {
|
||||
|
||||
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||
style.wmts_link = 'http://wmts.maptiler.com/' +
|
||||
base64url('http://' + req.headers.host +
|
||||
'/styles/' + id + '.json' + query) + '/wmts';
|
||||
base64url(utils.getPublicUrl(opts.publicUrl, req) +
|
||||
'styles/' + id + '.json' + query) + '/wmts';
|
||||
|
||||
var tiles = utils.getTileUrls(
|
||||
req, style.serving_rendered.tiles,
|
||||
@@ -322,8 +323,8 @@ function start(opts) {
|
||||
|
||||
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||
data_.wmts_link = 'http://wmts.maptiler.com/' +
|
||||
base64url('http://' + req.headers.host +
|
||||
'/data/' + id + '.json' + query) + '/wmts';
|
||||
base64url(utils.getPublicUrl(opts.publicUrl, req) +
|
||||
'data/' + id + '.json' + query) + '/wmts';
|
||||
|
||||
var tiles = utils.getTileUrls(
|
||||
req, data_.tiles, 'data/' + id, data_.format, {
|
||||
|
||||
@@ -6,6 +6,11 @@ var path = require('path'),
|
||||
var clone = require('clone'),
|
||||
glyphCompose = require('glyph-pbf-composite');
|
||||
|
||||
|
||||
module.exports.getPublicUrl = function(publicUrl, req) {
|
||||
return publicUrl || (req.protocol + '://' + req.headers.host + '/')
|
||||
}
|
||||
|
||||
module.exports.getTileUrls = function(req, domains, path, format, aliases) {
|
||||
|
||||
if (domains) {
|
||||
|
||||
Reference in New Issue
Block a user