Browse Source

tidy.. upgrade log-stats

master
Lloyd Brookes 9 years ago
parent
commit
c6588b466f
  1. 45
      lib/local-web-server.js
  2. 2
      package.json

45
lib/local-web-server.js

@ -14,6 +14,7 @@ const _ = require('koa-route')
const mount = require('koa-mount') const mount = require('koa-mount')
const httpProxy = require('http-proxy') const httpProxy = require('http-proxy')
const pathToRegexp = require('path-to-regexp') const pathToRegexp = require('path-to-regexp')
const http = require('http')
/** /**
* @module local-web-server * @module local-web-server
@ -42,40 +43,7 @@ function getApp (options) {
changeOrigin: true 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 => { options.proxyRoutes.forEach(route => {
app.use(_.all(route.from, function * () { app.use(_.all(route.from, function * () {
const keys = [] const keys = []
@ -91,13 +59,6 @@ function getApp (options) {
route.new = route.new route.new = route.new
.replace(re.token, arguments[index] || '') .replace(re.token, arguments[index] || '')
.replace(re.index, 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) { proxy.once('proxyReq', function (proxyReq) {
proxyReq.path = route.new; proxyReq.path = route.new;
@ -113,7 +74,7 @@ function getApp (options) {
if (options.blacklist.length) { if (options.blacklist.length) {
app.use(function pathBlacklist (ctx, next) { app.use(function pathBlacklist (ctx, next) {
if (options.blacklist.some(regexp => regexp.test(ctx.path))) { if (options.blacklist.some(regexp => regexp.test(ctx.path))) {
ctx.throw(403, 'Blacklisted')
ctx.throw(403, http.STATUS_CODES[403])
} else { } else {
return next() return next()
} }

2
package.json

@ -46,7 +46,7 @@
"morgan": "^1.0.0", "morgan": "^1.0.0",
"path-to-regexp": "^1.2.1", "path-to-regexp": "^1.2.1",
"req-then": "^0.2.2", "req-then": "^0.2.2",
"stream-log-stats": "^1"
"stream-log-stats": "^v1.1.0-0"
}, },
"devDependencies": { "devDependencies": {
"tape": "^4.2.2" "tape": "^4.2.2"

Loading…
Cancel
Save