This commit is contained in:
Lloyd Brookes
2015-11-24 11:46:47 +00:00
parent d963222d19
commit ccaae1614c
10 changed files with 121 additions and 151 deletions

View File

@ -44,7 +44,8 @@ function localWebServer (options) {
mime: {},
forbid: [],
rewrite: [],
verbose: false
verbose: false,
mocks: []
}, options)
if (options.verbose) {
@ -106,7 +107,7 @@ function localWebServer (options) {
app.use(mw.blacklist(options.forbid))
}
/* Cache */
/* cache */
if (!options['no-cache']) {
const conditional = require('koa-conditional-get')
const etag = require('koa-etag')
@ -144,7 +145,21 @@ function localWebServer (options) {
}
/* Mock Responses */
app.use(mw.mockResponses({ root: options.static.root }))
options.mocks.forEach(mock => {
if (mock.module) {
mock.targets = require(path.join(options.static.root, mock.module))
}
if (mock.targets) {
app.use(mw.mockResponses(mock.route, mock.targets))
} else if (mock.response) {
mock.target = {
request: mock.request,
response: mock.response
}
app.use(mw.mockResponses(mock.route, mock.target))
}
})
/* serve static files */
if (options.static.root) {