Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mutable/proxy

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mutable/proxy - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

2

package.json
{
"name": "@mutable/proxy",
"version": "2.0.1",
"version": "2.0.2",
"description": "Proxy",

@@ -5,0 +5,0 @@ "author": "pellepelle3",

@@ -57,6 +57,2 @@ const fs = require('fs');

function RoutePage404(res, content) {
SendWeb(res, content || '404', 404);
}
function HasEncryptedConnection(req) {

@@ -81,35 +77,6 @@ return req.connection.encrypted || req.connection.pair;

function OnError(err, req, res) {
TimeTrack(req, '_onError');
if (!err || !err.code) return RoutePage500(res);
if (err.code === 'ECONNREFUSED') return RoutePage500(res, 'Error with ECONNREFUSED');
return RoutePage404(res);
}
function CheckRoutes(req, res) {
const theUrlis = Url.parse(`http://${req.headers.host}${req.url}`);
switch (theUrlis.pathname) {
case '/health':
res.end(`${tooBusy.lag()}`);
break;
default:
RoutePage404(res);
}
}
function IsLocal(req, res) {
if (
req.headers.host === `${process.env.MYIP}:${process.env.PORT}`
|| (!IsIP.test(req.headers.host)
&& req.headers.host !== `${process.env.MYHOST || 'localhost'}:${process.env.PORT}`
&& req.headers.host !== `${process.env.HOSTNAME || ''}:${process.env.PORT}`)
) return false;
CheckRoutes(req, res);
return true;
}
class Proxy {
constructor(config) {
this._proxy = httpProxy.createProxyServer({ ws: true, xfwd: false });
this._proxy.on('error', (err, req, res) => OnError(err, req, res));
this._proxy.on('error', (err, req, res) => this._onError(err, req, res));
this._proxy.on('proxyRes', (proxyRes, req) => TimeTrack(req, '_onProxyRes'));

@@ -136,3 +103,3 @@ this._routes = new Routes(config);

_proxyingWeb(req, res) {
if (!IsLocal(req, res)) {
if (!this._isLocal(req, res)) {
DebugPrint('_proxyingWeb', req.headers.host + req.url);

@@ -148,3 +115,3 @@ TimeTrack(req, '_proxyingWeb');

_proxyingWebSockets(req, res, socket, head) {
if (!IsLocal(req, res)) {
if (!this._isLocal(req, res)) {
this._routes

@@ -204,7 +171,40 @@ .getTarget(`http://${req.headers.host}${req.url}`)

} else {
CheckRoutes(req, res);
this._checkRoutes(req, res);
}
}
_routePage404(res) {
SendWeb(res, this._page404 || '404', 404);
}
_onError(err, req, res) {
TimeTrack(req, '_onError');
if (!err || !err.code) return RoutePage500(res);
if (err.code === 'ECONNREFUSED') return RoutePage500(res, 'Error with ECONNREFUSED');
return this._routePage404(res);
}
_checkRoutes(req, res) {
const theUrlis = Url.parse(`http://${req.headers.host}${req.url}`);
switch (theUrlis.pathname) {
case '/health':
res.end(`${tooBusy.lag()}`);
break;
default:
this._routePage404(res);
}
}
_isLocal(req, res) {
if (
req.headers.host === `${process.env.MYIP}:${process.env.PORT}`
|| (!IsIP.test(req.headers.host)
&& req.headers.host !== `${process.env.MYHOST || 'localhost'}:${process.env.PORT}`
&& req.headers.host !== `${process.env.HOSTNAME || ''}:${process.env.PORT}`)
) return false;
this._checkRoutes(req, res);
return true;
}
}
module.exports = Proxy;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc