buddy-tunnel
Advanced tools
Comparing version 1.0.19-dev to 1.0.20-dev
{ | ||
"name": "buddy-tunnel", | ||
"preferGlobal": false, | ||
"version": "1.0.19-dev", | ||
"version": "1.0.20-dev", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -15,2 +15,3 @@ import fetch from 'node-fetch'; | ||
ERR_FAILED_TO_CONNECT, | ||
ERR_WRONG_TOKEN, | ||
LOG_AGENT_REGISTERED, | ||
@@ -26,6 +27,7 @@ LOG_GETTING_AGENT, | ||
const TIMEOUT = 30000; | ||
const TIMEOUT = 60000; | ||
class ApiErrorAgentNotFound extends Error {} | ||
class ApiErrorFailedToConnect extends Error {} | ||
class ApiErrorWrongToken extends Error {} | ||
@@ -58,2 +60,4 @@ const makeRequest = async (host, path, body, method = 'POST', respAsJson = true) => { | ||
throw new ApiErrorAgentNotFound(ERR_AGENT_REMOVED); | ||
} else if (data.result.code === 234020) { | ||
throw new ApiErrorWrongToken(ERR_WRONG_TOKEN); | ||
} else { | ||
@@ -60,0 +64,0 @@ throw new ApiErrorFailedToConnect(ERR_FAILED_TO_CONNECT(host)); |
@@ -19,4 +19,3 @@ import { Command } from 'commander'; | ||
process.on('uncaughtException', (err) => { | ||
if (process.env.DEBUG === '1') logger.fatal(err); | ||
else logger.fatal(err.message); | ||
logger.fatal(err); | ||
Output.exitError(err); | ||
@@ -23,0 +22,0 @@ }); |
@@ -51,3 +51,2 @@ import { Client } from 'ssh2'; | ||
this.client.connect({ | ||
keepalive: this.keepalive, | ||
host: this.ip, | ||
@@ -54,0 +53,0 @@ port: this.port, |
@@ -72,6 +72,8 @@ import EventEmitter from 'events'; | ||
try { | ||
const s = new stream.Readable(); | ||
s.push(html); | ||
s.push(null); | ||
s.pipe(this.logRequest.responseBody); | ||
if (this.logRequest) { | ||
const s = new stream.Readable(); | ||
s.push(html); | ||
s.push(null); | ||
s.pipe(this.logRequest.responseBody); | ||
} | ||
this.httpLog.newResponse(this.req, code, {}, this.logRequest); | ||
@@ -211,3 +213,7 @@ this.res.statusCode = code; | ||
this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod)); | ||
this.proxyRes.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
if (this.logRequest) { | ||
this.proxyRes.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} else { | ||
this.proxyRes.pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} | ||
this.httpLog.newResponse(this.req, statusCode, resHeaders, this.logRequest); | ||
@@ -245,3 +251,7 @@ }); | ||
this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod)); | ||
this.proxyRes.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
if (this.logRequest) { | ||
this.proxyRes.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} else { | ||
this.proxyRes.pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} | ||
this.httpLog.newResponse(this.req, statusCode, resHeaders, this.logRequest); | ||
@@ -265,3 +275,7 @@ }); | ||
this.outputHeaders(statusCode, this.getClearedHeaders(resHeaders, compressionMethod)); | ||
stream.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
if (this.logRequest) { | ||
stream.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} else { | ||
stream.pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} | ||
} | ||
@@ -290,3 +304,7 @@ this.httpLog.newResponse(this.req, statusCode, resHeaders, this.logRequest); | ||
this.outputHeaders(status, this.getClearedHeaders(resHeaders, compressionMethod)); | ||
r.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
if (this.logRequest) { | ||
r.pipe(this.logRequest.responseBody).pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} else { | ||
r.pipe(TunnelCompression.compress(compressionMethod)).pipe(this.res); | ||
} | ||
this.httpLog.newResponse(this.req, status, resHeaders, this.logRequest); | ||
@@ -293,0 +311,0 @@ }); |
@@ -5,2 +5,3 @@ import EventEmitter from 'events'; | ||
import TunnelHttpStream from './stream.js'; | ||
import { isBinaryFileSync } from 'isbinaryfile'; | ||
@@ -11,3 +12,3 @@ const TUNNEL_HTTP_RATE_LIMIT = 2000; | ||
const TUNNEL_HTTP_LOG_MAX_REQUESTS = 20; | ||
const TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = 1048576; // 1MB | ||
const TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = 25600; // 25kB (1 request do frontu moze miec max 1MB, 20 requestow po req i res body) | ||
const TUNNEL_HTTP_CB_WINDOW = 10000; | ||
@@ -145,12 +146,18 @@ const TUNNEL_HTTP_CB_MIN_REQUESTS = 20; | ||
this.requests.forEach((r) => { | ||
const [s] = process.hrtime(r.start); | ||
// do not sync requests older that 15m | ||
if (s >= 900) return; | ||
let requestBody = null; | ||
let requestBodyLength = 0; | ||
let requestBodyTooLarge = false; | ||
let requestBodyBinary = false; | ||
let responseBody = null; | ||
let responseBodyLength = 0; | ||
let responseBodyTooLarge = false; | ||
let responseBodyBinary = false; | ||
if (r.requestBody.realLength > 0) { | ||
requestBodyLength = r.requestBody.realLength; | ||
requestBodyTooLarge = r.requestBody.tooLarge; | ||
if (r.requestBody.data.length <= TUNNEL_MAX_REQUEST_SIZE_TO_SYNC) { | ||
requestBodyTooLarge = r.requestBody.tooLarge || r.requestBody.data.length >= TUNNEL_MAX_REQUEST_SIZE_TO_SYNC; | ||
requestBodyBinary = isBinaryFileSync(r.requestBody.data); | ||
if (!requestBodyTooLarge) { | ||
requestBody = r.requestBody.data.toString('base64'); | ||
@@ -161,4 +168,5 @@ } | ||
responseBodyLength = r.responseBody.realLength; | ||
responseBodyTooLarge = r.responseBody.tooLarge; | ||
if (r.responseBody.data.length <= TUNNEL_MAX_REQUEST_SIZE_TO_SYNC) { | ||
responseBodyTooLarge = r.responseBody.tooLarge || r.responseBody.data.length >= TUNNEL_MAX_REQUEST_SIZE_TO_SYNC; | ||
responseBodyBinary = isBinaryFileSync(r.requestBody.data); | ||
if (!responseBodyTooLarge) { | ||
responseBody = r.responseBody.data.toString('base64'); | ||
@@ -179,5 +187,7 @@ } | ||
requestBodyTooLarge, | ||
requestBodyBinary, | ||
requestBodyLength, | ||
responseBody, | ||
responseBodyTooLarge, | ||
responseBodyBinary, | ||
responseBodyLength | ||
@@ -184,0 +194,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301149
6889
14