Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jabis Sevón
/
esm
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
24a8bd35
authored
2016-08-20 11:56:02 +0200
by
Rafal Wilinski
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add dynamic title rendered only once, improve PR #25
1 parent
c34978d7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
index.html
index.js
index.html
View file @
24a8bd3
<!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>
...
...
index.js
View file @
24a8bd3
...
...
@@ -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
);
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment