diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfdef135..980a4972 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,6 +66,9 @@ importers: async-exit-hook: specifier: ^2.0.1 version: 2.0.1 + cookie: + specifier: ^0.7.1 + version: 0.7.1 lru-cache: specifier: ^7.14.1 version: 7.18.3 @@ -105,7 +108,7 @@ importers: dependencies: '@rubynetwork/rh': specifier: latest - version: 1.2.68(bufferutil@4.0.8) + version: 1.2.71(bufferutil@4.0.8) commander: specifier: ^12.0.0 version: 12.1.0 @@ -1071,8 +1074,8 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@rubynetwork/rh@1.2.68': - resolution: {integrity: sha512-6LSFs2paa0gdgyDNwGr0zXBJQfwb1pS0hkSQHIV5EuQMBcgZiZwTOiSCyo8faeJKHDaglLJCbcJ+XnbK4RyHyQ==} + '@rubynetwork/rh@1.2.71': + resolution: {integrity: sha512-nx7aDfC25ZzwK0zIMEbImKf2cv72h0Y5mYs5G/E3+rkhp36rAHNVrWV5QWYuPRMtudeiJpiMaei3i4F5KxtzDg==} '@types/estree@0.0.46': resolution: {integrity: sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==} @@ -1302,6 +1305,10 @@ packages: convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} + cookie@0.7.1: + resolution: {integrity: sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==} + engines: {node: '>= 0.6'} + core-js-compat@3.38.0: resolution: {integrity: sha512-75LAicdLa4OJVwFxFbQR3NdnZjNgX6ILpVcVzcC4T2smerB5lELMrJQQQoWV6TiuC/vlaFqgU2tKQx9w5s0e0A==} @@ -1442,9 +1449,6 @@ packages: engines: {node: ^10.12.0 || >=12.0.0} hasBin: true - esotope-hammerhead@0.6.5: - resolution: {integrity: sha512-vjncN4nG+RvsUNFC0idHNw1Xzse8GUWn15tr8In0Q4EBscnELTdpQVfsF/cRsMlvSbJdd0gUrW6gK5U+LTmVCg==} - esotope-hammerhead@0.6.8: resolution: {integrity: sha512-2Zhg0c6NfrNA4QT5s4+QG5WJQtq3Se7GonNwtNwfr7sVIo/7L8rirPfh9yyloEmDA7R0yPgD10teFxhf2vWyIw==} @@ -2236,10 +2240,6 @@ packages: resolution: {integrity: sha512-wK0Ri4fOGjv/XPy8SBHZChl8CM7uMc5VML7SqiQ0zG7+J5Vr+RMQDoHa2CNT6KHUnTGIXH34UDMkPzAUyapBZg==} engines: {node: '>=8'} - testcafe-hammerhead@31.6.2: - resolution: {integrity: sha512-0whraISoT70LN9K6y1zgti30/M0seYVWlODZCWhUlDPZHSQDZaSj2G6QSamj2hfaki6DAB1qnE5x2FA8TvJcYA==} - engines: {node: '>=14.0.0'} - testcafe-hammerhead@31.7.2: resolution: {integrity: sha512-wjZ3Y4fXnew6WaoMhD7jTe/zrzSYJMLZulX+/pXS6xed9meUx7zzCSc5epPJEW8Xy3Zo09n7w+m7+2SDej0/Iw==} engines: {node: '>=14.0.0'} @@ -3621,13 +3621,13 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@rubynetwork/rh@1.2.68(bufferutil@4.0.8)': + '@rubynetwork/rh@1.2.71(bufferutil@4.0.8)': dependencies: async-exit-hook: 2.0.1 lru-cache: 7.18.3 mime: 2.6.0 sticky-session-custom: 1.2.1 - testcafe-hammerhead: 31.6.2(bufferutil@4.0.8) + testcafe-hammerhead: 31.7.2(bufferutil@4.0.8) uglify-js: 3.19.1 uuid: 8.3.2 ws: 8.18.0(bufferutil@4.0.8) @@ -3872,6 +3872,8 @@ snapshots: convert-source-map@2.0.0: {} + cookie@0.7.1: {} + core-js-compat@3.38.0: dependencies: browserslist: 4.23.3 @@ -4047,10 +4049,6 @@ snapshots: transitivePeerDependencies: - supports-color - esotope-hammerhead@0.6.5: - dependencies: - '@types/estree': 0.0.46 - esotope-hammerhead@0.6.8: dependencies: '@types/estree': 0.0.46 @@ -4784,38 +4782,6 @@ snapshots: term-size@2.2.1: {} - testcafe-hammerhead@31.6.2(bufferutil@4.0.8): - dependencies: - '@adobe/css-tools': 4.4.0 - '@electron/asar': 3.2.10 - acorn-hammerhead: 0.6.2 - bowser: 1.6.0 - crypto-md5: 1.0.0 - debug: 4.3.1 - esotope-hammerhead: 0.6.5 - http-cache-semantics: 4.1.1 - httpntlm: 1.8.13 - iconv-lite: 0.5.1 - lodash: 4.17.21 - lru-cache: 2.6.3 - match-url-wildcard: 0.0.4 - merge-stream: 1.0.1 - mime: 1.4.1 - mustache: 2.3.2 - nanoid: 3.3.7 - os-family: 1.1.0 - parse5: 7.1.2 - pinkie: 2.0.4 - read-file-relative: 1.2.0 - semver: 7.5.3 - tough-cookie: 4.1.3 - tunnel-agent: 0.6.0 - ws: 7.5.10(bufferutil@4.0.8) - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - testcafe-hammerhead@31.7.2(bufferutil@4.0.8): dependencies: '@adobe/css-tools': 4.4.0 diff --git a/rammerhead/CHANGELOG.md b/rammerhead/CHANGELOG.md index 014793a4..5d672773 100644 --- a/rammerhead/CHANGELOG.md +++ b/rammerhead/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.2.72 + +- Hopefully fix the errors when running behind a reverse proxy + ## v1.2.70 - Setup folder properly diff --git a/rammerhead/package.json b/rammerhead/package.json index 9495aead..ddb31a10 100644 --- a/rammerhead/package.json +++ b/rammerhead/package.json @@ -1,6 +1,6 @@ { "name": "@rubynetwork/rh", - "version": "1.2.71", + "version": "1.2.72", "description": "User friendly web proxy powered by testcafe-hammerhead", "main": "src/index.js", "type": "module", @@ -27,6 +27,7 @@ "homepage": "https://github.com/binary-person/rammerhead#readme", "dependencies": { "async-exit-hook": "^2.0.1", + "cookie": "^0.7.1", "lru-cache": "^7.14.1", "mime": "^2.5.2", "sticky-session-custom": "^1.2.0", diff --git a/rammerhead/src/config.js b/rammerhead/src/config.js index cee32209..f784c184 100644 --- a/rammerhead/src/config.js +++ b/rammerhead/src/config.js @@ -1,6 +1,7 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; +import cookie from 'cookie'; import RammerheadJSFileCache from './classes/RammerheadJSFileCache.js'; import RammerheadJSMemCache from './classes/RammerheadJSMemCache.js'; @@ -25,12 +26,29 @@ export default { // this function's return object will determine how the client url rewriting will work. // set them differently from bindingAddress and port if rammerhead is being served // from a reverse proxy. - getServerInfo: () => ({ - hostname: 'localhost', - port: 8080, - crossDomainPort: 8081, - protocol: 'http:' - }), + //getServerInfo: () => ({ + // hostname: 'localhost', + // port: 8080, + // crossDomainPort: 8081, + // protocol: 'http:' + //}), + getServerInfo: (req) => { + const { origin_proxy } = cookie.parse(req.headers.cookie || ''); + let origin; + try { + origin = new URL(origin_proxy); + } catch (err) { + console.log(err, req.headers.cookie); + origin = new URL(`${req.socket.encrypted ? 'https:' : 'http:'}//${req.headers.host}`); + } + const { hostname, port, protocol } = origin; + return { + hostname, + port, + crossDomainPort: port, + protocol + }; + }, // example of non-hard-coding the hostname header // getServerInfo: (req) => { // return { hostname: new URL('http://' + req.headers.host).hostname, port: 443, crossDomainPort: 8443, protocol: 'https: }; diff --git a/rammerhead/src/setup.js b/rammerhead/src/setup.js index 22a5c506..c883c1d3 100644 --- a/rammerhead/src/setup.js +++ b/rammerhead/src/setup.js @@ -9,8 +9,7 @@ function setup() { fs.mkdirSync(path.join(import.meta.dirname, '..', 'public')); } catch (err) { - //steam roll over errors :D - //console.error('Something went wrong!\n', err) + console.error('Error occured while setting up:', err); } }