index.js 1.32 KB
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)
  }
}