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
32
33
34
35
36
37
38
const path = require('path')
const express = require('express')
const url = require('url')
const publicDir = path.resolve(__dirname, '..', 'publicIstanbulab')
const coverage = require(path.resolve(__dirname, '..', 'autoIstanbulLib/autoIstanbulHandlers'))
const bodyParser = require('body-parser')
function matcher(req) {
var parsed = url.parse(req.url)
return parsed.pathname && parsed.pathname.match(/\.js$/) && !parsed.pathname.match(/jquery/)
}
function list(req, res, next) {
var parsed = url.parse(req.url, true),
authors = data.authors;
if (parsed.query.alive === '1' || !coverage.getPitchingPile) {
authors = authors.filter(function (a) { return !a.deceased; });
}
res.render('index', { authors: authors });
}
module.exports = {
serve: function (port, needCover) {
var app = express()
if (needCover) {
console.log('Turn on coverage reporting at /coverage')
app.use('/coverage', coverage.createHandler({ verbose: true, resetOnGet: true }, false))
app.use(coverage.createClientHandler(publicDir, { matcher: matcher }))
}
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.set('view engine', 'hbs');
app.engine('hbs', require('hbs').__express);
app.use(express['static'](publicDir))
app.get('/', list);
app.listen(port)
}
}