diff --git a/.travis.yml b/.travis.yml index 33c817e..2e65ce1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: -- 'node' -- '4.2' +- '5' +- '4' diff --git a/bin/cli.js b/bin/cli.js index 6a2a909..1c763e2 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -6,7 +6,6 @@ const commandLineArgs = require('command-line-args') const ansi = require('ansi-escape-sequences') const loadConfig = require('config-master') const path = require('path') -const s = require('string-tools') const os = require('os') const arrayify = require('array-back') const t = require('typical') diff --git a/example/rewrite/.local-web-server.json b/example/rewrite/.local-web-server.json index ae46592..9e5755c 100644 --- a/example/rewrite/.local-web-server.json +++ b/example/rewrite/.local-web-server.json @@ -2,6 +2,10 @@ "rewrite": [ { "from": "/css/*", "to": "/build/styles/$1" }, { "from": "/npm/*", "to": "http://registry.npmjs.org/$1" }, - { "from": "/:user/repos/:name", "to": "https://api.github.com/repos/:user/:name" } + { "from": "/:user/repos/:name", "to": "https://api.github.com/repos/:user/:name" }, + { + "from": "/lloyd/*", + "to": "http://104.131.40.69/$1" + } ] } diff --git a/lib/middleware.js b/lib/middleware.js index ecacc43..da1e5e3 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -78,7 +78,7 @@ function mime (mimeTypes) { function mockResponses (route, targets) { targets = arrayify(targets) - debug('mock route: %s, targets: %s', route, targets.length); + debug('mock route: %s, targets: %s', route, targets.length) const pathRe = pathToRegexp(route) return function mockResponse (ctx, next) { @@ -103,13 +103,12 @@ function mockResponses (route, targets) { if (target) { if (t.isFunction(target.response)) { const pathMatches = ctx.path.match(pathRe).slice(1) - return target.response.apply(null, [ctx].concat(pathMatches)) + return target.response.apply(null, [ctx].concat(pathMatches)) } else if (t.isPlainObject(target.response)) { Object.assign(ctx.response, target.response) } else { throw new Error(`Invalid response: ${JSON.stringify(target.response)}`) } - } } else { return next() diff --git a/test/test.js b/test/test.js index a5da31b..4231b6d 100644 --- a/test/test.js +++ b/test/test.js @@ -259,9 +259,9 @@ test('mock: accepts request filter', function (t) { }) const server = http.createServer(app.callback()) server.listen(8100, () => { - request('http://localhost:8100/test', { headers: { Accept: '*/json' }}) + request('http://localhost:8100/test', { headers: { Accept: '*/json' } }) .then(checkResponse(t, 404)) - .then(() => request('http://localhost:8100/test', { headers: { Accept: 'text/plain' }})) + .then(() => request('http://localhost:8100/test', { headers: { Accept: 'text/plain' } })) .then(checkResponse(t, 200, /test/)) .then(server.close.bind(server)) })