fix /style/id.json with next('route')
Co-Authored-By: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
parent
4c6f379f4e
commit
592e74c303
1 changed files with 23 additions and 16 deletions
|
@ -445,17 +445,16 @@ async function start(opts) {
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(templateFile, 'utf-8');
|
const content = fs.readFileSync(templateFile, 'utf-8');
|
||||||
const compiled = handlebars.compile(content.toString());
|
const compiled = handlebars.compile(content.toString());
|
||||||
app.get(urlPath, (req, res) => {
|
app.get(urlPath, (req, res, next) => {
|
||||||
|
if (opts.verbose) {
|
||||||
console.log(`Serving template at path: ${urlPath}`);
|
console.log(`Serving template at path: ${urlPath}`);
|
||||||
|
}
|
||||||
let data = {};
|
let data = {};
|
||||||
if (dataGetter) {
|
if (dataGetter) {
|
||||||
data = dataGetter(req);
|
data = dataGetter(req);
|
||||||
if (!data) {
|
if (data) {
|
||||||
console.error(`Data getter for ${template} returned null`);
|
data['server_version'] =
|
||||||
return res.status(404).send('Not found');
|
`${packageJson.name} v${packageJson.version}`;
|
||||||
}
|
|
||||||
}
|
|
||||||
data['server_version'] = `${packageJson.name} v${packageJson.version}`;
|
|
||||||
data['public_url'] = opts.publicUrl || '/';
|
data['public_url'] = opts.publicUrl || '/';
|
||||||
data['is_light'] = isLight;
|
data['is_light'] = isLight;
|
||||||
data['key_query_part'] = req.query.key
|
data['key_query_part'] = req.query.key
|
||||||
|
@ -466,12 +465,20 @@ async function start(opts) {
|
||||||
: '';
|
: '';
|
||||||
if (template === 'wmts') res.set('Content-Type', 'text/xml');
|
if (template === 'wmts') res.set('Content-Type', 'text/xml');
|
||||||
return res.status(200).send(compiled(data));
|
return res.status(200).send(compiled(data));
|
||||||
|
} else {
|
||||||
|
if (opts.verbose) {
|
||||||
|
console.log(`Forwarding request for: ${urlPath} to next route`);
|
||||||
|
}
|
||||||
|
next('route');
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Error reading template file: ${templateFile}`, err);
|
console.error(`Error reading template file: ${templateFile}`, err);
|
||||||
throw new Error(`Template not found: ${err.message}`); //throw an error so that the server doesnt start
|
throw new Error(`Template not found: ${err.message}`); //throw an error so that the server doesnt start
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serveTemplate('/', 'index', (req) => {
|
serveTemplate('/', 'index', (req) => {
|
||||||
let styles = {};
|
let styles = {};
|
||||||
for (const id of Object.keys(serving.styles || {})) {
|
for (const id of Object.keys(serving.styles || {})) {
|
||||||
|
|
Loading…
Reference in a new issue