From c6588b466f17c0f8acfbc7aaf709e9bd7b9be3dd Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Sun, 15 Nov 2015 12:29:43 +0000 Subject: [PATCH] tidy.. upgrade log-stats --- lib/local-web-server.js | 45 +++------------------------------------------ package.json | 2 +- 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/lib/local-web-server.js b/lib/local-web-server.js index ca081fc..aada8af 100644 --- a/lib/local-web-server.js +++ b/lib/local-web-server.js @@ -14,6 +14,7 @@ const _ = require('koa-route') const mount = require('koa-mount') const httpProxy = require('http-proxy') const pathToRegexp = require('path-to-regexp') +const http = require('http') /** * @module local-web-server @@ -42,40 +43,7 @@ function getApp (options) { changeOrigin: true }) - // app.use(_.all('/api/*', function * (apiPath) { - // this.response = false - // proxy.once('proxyReq', function (proxyReq, req, res, options) { - // proxyReq.path = `http://registry.npmjs.org/${apiPath}`; - // }) - // proxy.web(this.req, this.res, { target: `http://registry.npmjs.org/${apiPath}` }) - // })) - // app.use(mount('/gh', function * (next) { - // this.response = false - // proxy.web(this.req, this.res, { target: 'https://api.github.com' }) - // })) - // app.use(_.get('/:one/gh/:two', function * (one, two) { - // this.response = false - // proxy.once('proxyReq', function (proxyReq, req, res, options) { - // proxyReq.path = `https://api.github.com/${one}/${two}`; - // }) - // proxy.web(this.req, this.res, { target: `https://api.github.com/${one}/${two}` }) - // })) - // app.use(_.get('/*/yeah/:one/*', function * (one, two) { - // console.log(arguments); - // this.response = false - // proxy.once('proxyReq', function (proxyReq, req, res, options) { - // proxyReq.path = `https://api.github.com/${one}/${two}`; - // }) - // proxy.web(this.req, this.res, { target: `https://api.github.com/${one}/${two}` }) - // })) - - // const proxyRoutes = [ - // // { mount: '/api', to: 'http://registry.npmjs.org' }, - // // { mount: '/gh', to: 'http://https://api.github.com' }, - // { from: '/:one/gh/:two', to: 'https://api.github.com/${one}/${two}' }, - // { from: '/api/*', to: 'http://registry.npmjs.org/${0}' }, - // ] - + /* Proxy routes */ options.proxyRoutes.forEach(route => { app.use(_.all(route.from, function * () { const keys = [] @@ -91,13 +59,6 @@ function getApp (options) { route.new = route.new .replace(re.token, arguments[index] || '') .replace(re.index, arguments[index] || '') - - // console.log('=========='); - // console.log(arguments); - // console.log(re); - // console.log(index); - // console.log(route); - }) proxy.once('proxyReq', function (proxyReq) { proxyReq.path = route.new; @@ -113,7 +74,7 @@ function getApp (options) { if (options.blacklist.length) { app.use(function pathBlacklist (ctx, next) { if (options.blacklist.some(regexp => regexp.test(ctx.path))) { - ctx.throw(403, 'Blacklisted') + ctx.throw(403, http.STATUS_CODES[403]) } else { return next() } diff --git a/package.json b/package.json index 94ba584..b42e292 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "morgan": "^1.0.0", "path-to-regexp": "^1.2.1", "req-then": "^0.2.2", - "stream-log-stats": "^1" + "stream-log-stats": "^v1.1.0-0" }, "devDependencies": { "tape": "^4.2.2"