Add possibility to change the front page (close #128)
This commit is contained in:
parent
f8949c1aa9
commit
1e402ed207
2 changed files with 21 additions and 4 deletions
|
@ -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``
|
||||
-----------------
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue