logger common test

This commit is contained in:
Lloyd Brookes
2015-11-10 21:50:56 +00:00
parent c7a6bd15b6
commit 4edc00ca48
4 changed files with 49 additions and 7 deletions

View File

@ -2,8 +2,8 @@
const Koa = require('koa')
const serve = require('koa-static')
const convert = require('koa-convert')
const extend = require('deep-extend')
const serveIndex = require('koa-serve-index')
const morgan = require('koa-morgan')
/**
* @module local-web-server
@ -15,14 +15,22 @@ process.on('unhandledRejection', (reason, p) => {
})
function getApp (options) {
options = extend({
static: { root: '.' },
serveIndex: { path: '.' }
options = Object.assign({
static: {},
serveIndex: {},
logger: {}
}, options)
const app = new Koa()
app.use(convert(serve(options.static.root, options.static.options)))
app.use(convert(serveIndex(options.serveIndex.path, options.serveIndex.options)))
if (options.logger.format) {
app.use(convert(morgan.middleware(options.logger.format, options.logger.options)))
}
if (options.static.root) {
app.use(convert(serve(options.static.root, options.static.options)))
}
if (options.serveIndex.path) {
app.use(convert(serveIndex(options.serveIndex.path, options.serveIndex.options)))
}
return app
}