Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [v0.0.5]

- Fix https proxy requests.

## [v0.0.4](https://github.com/ontola/koa-http2-proxy/releases/tag/v0.0.4)

- handle errors caused by socket.destroy();
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-http2-proxy",
"version": "0.0.4",
"name": "@hvdb/koa-http2-proxy",
"version": "0.0.6",
"description": "Configure http2-proxy middleware with ease for koa.",
"main": "dist/index.js",
"files": [
Expand All @@ -24,7 +24,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/ontola/koa-http2-proxy.git"
"url": "https://github.com/hvdb/koa-http2-proxy.git"
},
"keywords": [
"reverse",
Expand All @@ -41,9 +41,9 @@
"author": "Steven Chim, Ontola BV",
"license": "MIT",
"bugs": {
"url": "https://github.com/ontola/koa-http2-proxy/issues"
"url": "https://github.com/hvdb/koa-http2-proxy/issues"
},
"homepage": "https://github.com/ontola/koa-http2-proxy",
"homepage": "https://github.com/hvdb/koa-http2-proxy",
"devDependencies": {
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
Expand Down Expand Up @@ -87,5 +87,9 @@
"extends": [
"@commitlint/config-conventional"
]
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
}
}
16 changes: 14 additions & 2 deletions src/koa-http2-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { request } from 'http';
import { request as requestHttp } from 'http';
import { request as requestHttps } from 'https';

import * as finalhandler from 'finalhandler';
import * as proxy from 'http2-proxy';
Expand Down Expand Up @@ -44,6 +45,7 @@ export class KoaHttp2Proxy {
proxy.web(
ctx.req,
ctx.res,
//@ts-ignore
this.prepareProxyRequest(ctx, resolve),
this.defaultWebHandler(ctx, resolve, reject)
)
Expand All @@ -60,7 +62,16 @@ export class KoaHttp2Proxy {
};

private handleReq = ctx => (req, options) => {
const proxyReq = request(options);
let proxyReq;
const target = this.applyRouter(req, this.proxyOptions);
const uri = url.parse(target);

if (uri.protocol === 'http:') {
proxyReq = requestHttp(options);
} else {
proxyReq = requestHttps(options);
}


if (!this.proxyOptions.changeOrigin) {
proxyReq.setHeader('host', req.headers.host);
Expand Down Expand Up @@ -111,6 +122,7 @@ export class KoaHttp2Proxy {
}

const activeProxyOptions = this.prepareProxyRequest(ctx, null);
//@ts-ignore
proxy.ws(req, socket, head, activeProxyOptions, this.defaultWSHandler);
this.logger.info('[HPM] Upgrading to WebSocket');
}
Expand Down