diff --git a/docs/config.rst b/docs/config.rst index 3ca6768..c430ed8 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -70,6 +70,14 @@ The value of ``root`` is used as prefix for all data types. You can use this to optionally specify on what domains the rendered tiles are accessible. This can be used for basic load-balancing or to bypass browser's limit for the number of connections per domain. +``frontPage`` +----------------- + +Path to the html (relative to ``root`` path) to use as a front page. + +Use ``true`` (or nothing) to serve the default TileServer GL front page with list of styles and data. +Use ``false`` to disable the front page altogether (404). + ``formatQuality`` ----------------- diff --git a/src/server.js b/src/server.js index e7a6796..5a6d8e1 100644 --- a/src/server.js +++ b/src/server.js @@ -209,14 +209,23 @@ module.exports = function(opts, callback) { app.use('/', express.static(path.join(__dirname, '../public/resources'))); var templates = path.join(__dirname, '../public/templates'); - var serveTemplate = function(path, template, dataGetter) { - fs.readFile(templates + '/' + template + '.tmpl', function(err, content) { + var serveTemplate = function(urlPath, template, dataGetter) { + var templateFile = templates + '/' + template + '.tmpl'; + if (template == 'index') { + if (options.frontPage === false) { + return; + } else if (options.frontPage && + options.frontPage.constructor === String) { + templateFile = path.resolve(paths.root, options.frontPage); + } + } + fs.readFile(templateFile, function(err, content) { if (err) { - console.log('Template not found:', err); + console.error('Template not found:', err); } var compiled = handlebars.compile(content.toString()); - app.use(path, function(req, res, next) { + app.use(urlPath, function(req, res, next) { var data = {}; if (dataGetter) { data = dataGetter(req);