add koa-json and bodyparser
This commit is contained in:
@ -57,8 +57,10 @@ function localWebServer (options) {
|
||||
const convert = require('koa-convert')
|
||||
const cors = require('kcors')
|
||||
const _ = require('koa-route')
|
||||
const json = require('koa-json')
|
||||
pathToRegexp = require('path-to-regexp')
|
||||
debug = require('debug')('local-web-server')
|
||||
const bodyParser = require('koa-bodyparser')
|
||||
|
||||
const log = options.log
|
||||
log.options = log.options || {}
|
||||
@ -81,6 +83,12 @@ function localWebServer (options) {
|
||||
/* CORS: allow from any origin */
|
||||
app.use(cors())
|
||||
|
||||
/* pretty print JSON */
|
||||
app.use(json())
|
||||
|
||||
/* request body parser */
|
||||
app.use(bodyParser())
|
||||
|
||||
/* rewrite rules */
|
||||
if (options.rewrite && options.rewrite.length) {
|
||||
options.rewrite.forEach(route => {
|
||||
@ -155,14 +163,12 @@ function localWebServer (options) {
|
||||
/* serve static files */
|
||||
if (options.static.root) {
|
||||
const serve = require('koa-static')
|
||||
// verbose('static', 'enabled')
|
||||
app.use(serve(options.static.root, options.static.options))
|
||||
}
|
||||
|
||||
/* serve directory index */
|
||||
if (options.serveIndex.path) {
|
||||
const serveIndex = require('koa-serve-index')
|
||||
// verbose('serve-index', 'enabled')
|
||||
app.use(serveIndex(options.serveIndex.path, options.serveIndex.options))
|
||||
}
|
||||
|
||||
@ -266,8 +272,8 @@ function mockResponses (options) {
|
||||
|
||||
if (mock) {
|
||||
Object.assign(ctx.response, mockedReponse)
|
||||
options.verbose('mocked response', JSON.stringify(mockedReponse))
|
||||
options.verbose('actual response', JSON.stringify(ctx.response))
|
||||
// options.verbose('mocked response', JSON.stringify(mockedReponse))
|
||||
// options.verbose('actual response', JSON.stringify(ctx.response))
|
||||
}
|
||||
} else {
|
||||
return next()
|
||||
|
Reference in New Issue
Block a user