rewrite: static and serve-index tests

This commit is contained in:
Lloyd Brookes
2015-11-08 22:09:07 +00:00
parent 867275a29d
commit c7a6bd15b6
8 changed files with 101 additions and 173 deletions

28
lib/local-web-server.js Normal file
View File

@ -0,0 +1,28 @@
'use strict'
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')
/**
* @module local-web-server
*/
module.exports = getApp
process.on('unhandledRejection', (reason, p) => {
throw reason
})
function getApp (options) {
options = extend({
static: { root: '.' },
serveIndex: { path: '.' }
}, 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)))
return app
}