Skip to content

Commit

Permalink
fix: Remove connection header from request
Browse files Browse the repository at this point in the history
Can cause issues in certain situations
  • Loading branch information
hofmeister committed Jan 2, 2024
1 parent 14af00c commit 00913ae
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 180 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ jobs:
holder: 'Kapeta Inc.'
license: 'MIT'
sources: '*.ts'

14 changes: 5 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# [1.1.0](https://github.com/kapetacom/sdk-nodejs-proxy-route/compare/v1.0.2...v1.1.0) (2023-12-13)


### Features

* Refactor to use plain express routes ([#4](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/4)) ([3482596](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/34825962fb55296e201eaa5814a3abe1b9eb01f6))
- Refactor to use plain express routes ([#4](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/4)) ([3482596](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/34825962fb55296e201eaa5814a3abe1b9eb01f6))

## [1.0.2](https://github.com/kapetacom/sdk-nodejs-proxy-route/compare/v1.0.1...v1.0.2) (2023-06-11)


### Bug Fixes

* Default to commonjs ([5f2c3be](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/5f2c3be5cdf96b7e17b20defa9b804daaff900aa))
- Default to commonjs ([5f2c3be](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/5f2c3be5cdf96b7e17b20defa9b804daaff900aa))

## [1.0.1](https://github.com/kapetacom/sdk-nodejs-proxy-route/compare/v1.0.0...v1.0.1) (2023-06-09)


### Bug Fixes

* Support mixed modules ([77956ea](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/77956eafec2f16bb51ba40dd80bb3c419092ce34))
- Support mixed modules ([77956ea](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/77956eafec2f16bb51ba40dd80bb3c419092ce34))

# 1.0.0 (2023-06-09)


### Features

* Allow proxying other port types ([#1](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/1)) ([f70968f](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/f70968f7f89f98eecebebf00246c5b0822d390ce))
* Rewrote to TS ([#2](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/2)) ([d750612](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/d7506121ba7723db7a2f966016d98506de0c2c06))
- Allow proxying other port types ([#1](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/1)) ([f70968f](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/f70968f7f89f98eecebebf00246c5b0822d390ce))
- Rewrote to TS ([#2](https://github.com/kapetacom/sdk-nodejs-proxy-route/issues/2)) ([d750612](https://github.com/kapetacom/sdk-nodejs-proxy-route/commit/d7506121ba7723db7a2f966016d98506de0c2c06))
35 changes: 28 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

import Path from 'path';

import { RequestHandler } from 'express';
import { RequestHandler, Request } from 'express';
import proxy from 'express-http-proxy';
import { ConfigProvider } from '@kapeta/sdk-config';

const DEFAULT_SERVICE_TYPE = 'web';

export const createProxyRoute = async (provider: ConfigProvider, name: string, serviceType?: string):Promise<RequestHandler> => {
export const createProxyRoute = async (
provider: ConfigProvider,
name: string,
serviceType?: string
): Promise<RequestHandler> => {
let targetUrl = await provider.getServiceAddress(name, serviceType ?? DEFAULT_SERVICE_TYPE);
if (!targetUrl) {
throw new Error(`Service ${name} not found`);
Expand All @@ -27,12 +31,29 @@ export const createProxyRoute = async (provider: ConfigProvider, name: string, s

return proxy(urlParts.host, {
https: urlParts.protocol === 'https',
proxyReqPathResolver: function (req) {
timeout: 120000,
limit: '1000mb',
preserveHostHdr: false,
parseReqBody: false,
memoizeHost: false,
proxyErrorHandler: function (err, res, next) {
console.error('Proxy error: %s', err.message);
next(err);
},
proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
if (proxyReqOpts.headers) {
delete proxyReqOpts.headers['connection'];
}
return proxyReqOpts;
},
proxyReqPathResolver: function (req: Request) {
const [path, query] = req.url.split('?');

return Path.join(urlParts.pathname, path) + (query ? '?' + query : '');
},
})
}
const out = Path.join(urlParts.pathname, path) + (query ? '?' + query : '');

console.log('Proxy request to %s > %s', req.url, out);

return out;
},
});
};
Loading

0 comments on commit 00913ae

Please sign in to comment.