-
Notifications
You must be signed in to change notification settings - Fork 4
/
about-page.js
31 lines (26 loc) · 773 Bytes
/
about-page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {stringifyEntitiesLight as escape} from 'stringify-entities'
const createAboutPageRoute = (name, description, docsLink) => {
if ('string' !== typeof name || !name) {
throw new Error('name must be a string.')
}
if ('string' !== typeof description || !description) {
throw new Error('description must be a string.')
}
if ('string' !== typeof docsLink || !docsLink) {
throw new Error('docsLink must be a string.')
}
const msg = `\
<h1><code>${escape(name)}</code></h1>
<p>${escape(description)}</p>
<p><a href="${escape(docsLink)}">documentation</a></p>`
const about = (req, res, next) => {
if (!req.accepts('html')) return next()
res.set('content-type', 'text/html')
res.send(msg)
next()
}
return about
}
export {
createAboutPageRoute,
}