Add possibility to change the front page (close #128)

This commit is contained in:
Petr Sloup 2017-03-15 15:50:58 +01:00
parent f8949c1aa9
commit 1e402ed207
2 changed files with 21 additions and 4 deletions

View file

@ -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. 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`` ``formatQuality``
----------------- -----------------

View file

@ -209,14 +209,23 @@ module.exports = function(opts, callback) {
app.use('/', express.static(path.join(__dirname, '../public/resources'))); app.use('/', express.static(path.join(__dirname, '../public/resources')));
var templates = path.join(__dirname, '../public/templates'); var templates = path.join(__dirname, '../public/templates');
var serveTemplate = function(path, template, dataGetter) { var serveTemplate = function(urlPath, template, dataGetter) {
fs.readFile(templates + '/' + template + '.tmpl', function(err, content) { 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) { if (err) {
console.log('Template not found:', err); console.error('Template not found:', err);
} }
var compiled = handlebars.compile(content.toString()); var compiled = handlebars.compile(content.toString());
app.use(path, function(req, res, next) { app.use(urlPath, function(req, res, next) {
var data = {}; var data = {};
if (dataGetter) { if (dataGetter) {
data = dataGetter(req); data = dataGetter(req);