Skip to content

Commit

Permalink
Merge pull request #40 from vagusX/feat/infra-update
Browse files Browse the repository at this point in the history
  • Loading branch information
vagusX committed Oct 11, 2019
2 parents 3204d4a + b52b1ac commit dc6780a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
extends:
- standard
plugins:
- mocha
env:
node: true
mocha: true
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Dependencies
*/
const url = require('url')
const { URL } = require('url')
const HttpProxy = require('http-proxy')
const pathMatch = require('path-match')

Expand Down Expand Up @@ -62,8 +62,9 @@ module.exports = (context, options) => (ctx, next) => {
// Let the promise be solved correctly after the proxy.web.
// The solution comes from https://github.com/nodejitsu/node-http-proxy/issues/951#issuecomment-179904134
ctx.res.on('close', () => {
reject(new Error(`Http response closed while proxying ${ctx.req.oldPath}`));
});
reject(new Error(`Http response closed while proxying ${ctx.req.oldPath}`))
})

ctx.res.on('finish', () => {
resolve()
})
Expand All @@ -82,5 +83,5 @@ module.exports = (context, options) => (ctx, next) => {
module.exports.proxy = proxy

function logger (ctx, target) {
console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, url.resolve(target, ctx.req.url))
console.log('%s - %s %s proxy to -> %s', new Date().toISOString(), ctx.req.method, ctx.req.oldPath, new URL(ctx.req.url, target))
}
31 changes: 23 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,49 @@
"semantic-release": "semantic-release",
"test": "nyc mocha",
"coverage": "nyc report --reporter=lcov --reporter=html && codecov -f .nyc_output/*.json",
"ci": "npm run test && npm run coverage"
"ci": "npm run test && npm run coverage",
"lint": "eslint index.js test/"
},
"repository": {
"type": "git",
"url": "https://github.com/vagusX/koa-proxies.git"
},
"config": {
"ghooks": {
"commit-msg": "node ./node_modules/.bin/validate-commit-msg"
}
},
"author": "vagusX",
"license": "MIT",
"bugs": {
"url": "https://github.com/vagusX/koa-proxies/issues"
},
"homepage": "https://github.com/vagusX/koa-proxies#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.js": "npm run lint"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"chai": "^4.1.2",
"chai-http": "^4.0.0",
"codecov": "^3.0.4",
"eslint": "^6.5.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-mocha": "^6.1.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"ghooks": "^2.0.2",
"husky": "^3.0.8",
"koa": "^2.5.2",
"lint-staged": "^10.0.0-0",
"mocha": "^5.2.0",
"nyc": "^13.2.0",
"semantic-release": "^15.1.5",
"sinon": "^7.2.4",
"validate-commit-message": "^3.0.1"
"sinon": "^7.2.4"
},
"dependencies": {
"http-proxy": "^1.16.2",
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('tests for koa proxies', () => {
logs: true,
events: {
proxyReq: proxyReqSpy,
proxyRes: proxyResSpy,
proxyRes: proxyResSpy
}
})

Expand Down
6 changes: 3 additions & 3 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const Koa = require('koa')

module.exports = {
startServer,
sleep,
sleep
}

function startServer(port, ...middlewares) {
function startServer (port, ...middlewares) {
const app = new Koa()
middlewares.forEach(middleware => {
app.use(middleware)
})
return app.listen(port)
}

function sleep(ms) {
function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

0 comments on commit dc6780a

Please sign in to comment.