rewrite: static and serve-index tests
This commit is contained in:
28
lib/local-web-server.js
Normal file
28
lib/local-web-server.js
Normal 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
|
||||
}
|
Reference in New Issue
Block a user