From b1bc8bed9613be3386bda616ec0e07e3bc0ed24b Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Sat, 1 Jul 2017 23:08:30 +0100 Subject: [PATCH] add lws-request-monitor --- README.md | 7 ++++--- lib/command/middleware-list.js | 1 + lib/command/serve.js | 1 + lib/local-web-server.js | 1 + package.json | 7 ++++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bec55e4..e748295 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:80 Another common use case is to **proxy certain requests to a remote server** if, for example, you'd like to use data from a different environment. The following command would proxy requests with a URL beginning with `http://127.0.0.1:8000/api/` to `https://internal-service.local/api/`: ```sh -$ ws --rewrite '/api/* -> https://internal-service.local/api/$1` +$ ws --rewrite '/api/* -> https://internal-service.local/api/$1' Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000 ``` @@ -73,8 +73,9 @@ module.exports = [ response: function (ctx) { const newUser = ctx.request.body users.push(newUser) + newUser.id = users.length ctx.status = 201 - ctx.response.set('Location', `/users/${users.length}`) + ctx.response.set('Location', `/users/${newUser.id}`) } } ] @@ -82,7 +83,7 @@ module.exports = [ ] ``` -Next, launch `ws` passing in your mock response file: +Next, launch `ws` passing in your mock response file: ```sh $ ws --mocks example-mocks.js diff --git a/lib/command/middleware-list.js b/lib/command/middleware-list.js index caf2f65..ed622a6 100644 --- a/lib/command/middleware-list.js +++ b/lib/command/middleware-list.js @@ -4,6 +4,7 @@ class MiddlewareList { } execute (options) { const list = [ + 'lws-request-monitor', 'lws-log', 'lws-cors', 'lws-json', diff --git a/lib/command/serve.js b/lib/command/serve.js index b1839a4..d81d2d7 100644 --- a/lib/command/serve.js +++ b/lib/command/serve.js @@ -14,6 +14,7 @@ class WsServe extends ServeCommand { .set('cd4', 'cli') options = { stack: [ + 'lws-request-monitor', 'lws-log', 'lws-cors', 'lws-json', diff --git a/lib/local-web-server.js b/lib/local-web-server.js index 67602af..92ac13d 100644 --- a/lib/local-web-server.js +++ b/lib/local-web-server.js @@ -12,6 +12,7 @@ class LocalWebServer extends Lws { moduleDir: path.resolve(__dirname, `../node_modules`), modulePrefix: 'lws-', stack: [ + 'lws-request-monitor', 'lws-log', 'lws-cors', 'lws-json', diff --git a/package.json b/package.json index 4e7d9b4..0367ca6 100644 --- a/package.json +++ b/package.json @@ -32,19 +32,20 @@ "repository": "https://github.com/lwsjs/local-web-server", "author": "Lloyd Brookes <75pound@gmail.com>", "dependencies": { - "lws": "^1.0.0-pre2.6", + "lws": "^1.0.0-pre2.7", "lws-blacklist": "^0.2.1", "lws-body-parser": "^0.2.2", "lws-compress": "^0.2.1", "lws-conditional-get": "^0.3.3", "lws-cors": "^0.3.2", - "lws-index": "^0.3.1", + "lws-index": "^0.3.2", "lws-json": "^0.3.2", "lws-log": "^0.3.0", "lws-mime": "^0.2.1", "lws-mock-response": "^0.2.3", + "lws-request-monitor": "^0.1.0", "lws-rewrite": "^0.3.4", - "lws-spa": "^0.2.1", + "lws-spa": "^0.2.2", "lws-static": "^0.3.4" }, "devDependencies": {