24a8bd35 by Rafal Wilinski

Add dynamic title rendered only once, improve PR #25

1 parent c34978d7
<!DOCTYPE html>
<html>
<head>
<title>Express Status</title>
<title>{{title}}</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js"></script>
<style>
......@@ -75,7 +75,7 @@
<body>
<div style="width: 600px; margin: auto">
<div class="header">
<b>Express Status</b>
<b>{{title}}</b>
<div id="span-controls" class="span-controls">
</div>
</div>
......
......@@ -73,6 +73,15 @@
config.spans = defaultConfig.spans;
}
if (config.title === undefined || !config instanceof String) {
config.title = 'Express Status';
}
let renderedHtml;
fs.readFile(path.join(__dirname, '/index.html'), function(err, html){
renderedHtml = html.toString().replace(/{{title}}/g, config.title);
});
return (req, res, next) => {
if (io === null || io === undefined) {
......@@ -92,12 +101,7 @@
const startTime = process.hrtime();
if (req.path === config.path) {
fs.readFile(path.join(__dirname + '/index.html'), function(err, content) {
content = content.toString().replace(new RegExp(defaultConfig.title, 'g'), config.title);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(content);
res.end();
});
res.send(renderedHtml);
} else {
onHeaders(res, () => {
const diff = process.hrtime(startTime);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!