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

foxy

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foxy - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

48

index.js

@@ -1,2 +0,2 @@

var lrSnippet = require("resp-modifier");
var respMod = require("resp-modifier");
var httpProxy = require("http-proxy");

@@ -7,14 +7,20 @@ var http = require("http");

function init(opts, proxyUrl) {
/**
* @param opts
* @param proxyUrl
* @param [additionalRules]
* @returns {*}
*/
function init(opts, proxy, additionalRules) {
var proxy = httpProxy.createProxyServer({ws: true, target: opts.target});
var middleware = lrSnippet({rules: [utils.rewriteLinks(opts, proxyUrl)]});
var proxyHost = proxy.host + ":" + proxy.port;
var proxyServer = httpProxy.createProxyServer({ws: true, target: opts.target});
var middleware = respMod({
rules: getRules()
});
var server = http.createServer(function(req, res) {
req.headers["accept-encoding"] = "identity";
var next = function () {
proxy.web(req, res, {
target: opts.target,
proxyServer.web(req, res, {
headers: {

@@ -25,6 +31,30 @@ host: utils.getProxyHost(opts)

};
utils.handleIe(req);
middleware(req, res, next);
});
// Remove headers
proxyServer.on("proxyRes", function (res) {
if (res.statusCode === 302) {
res.headers.location = utils.handleRedirect(res.headers.location, opts, proxyHost);
}
utils.removeHeaders(res.headers, ["content-length", "content-encoding"]);
});
function getRules() {
var rules = [utils.rewriteLinks(opts, proxyHost)];
if (additionalRules) {
if (Array.isArray(additionalRules)) {
additionalRules.forEach(function (rule) {
rules.push(rule);
})
} else {
rules.push(additionalRules);
}
}
return rules;
}
return server;

@@ -31,0 +61,0 @@ }

"use strict";
var url = require("url");
var path = require("path");
var excludeList = [
".js",
".css",
".pdf",
".map",
".svg",
".ico",
".woff",
".json",
".eot",
".ttf",
".png",
".jpg",
".jpeg",
".webp",
".gif",
".mp4",
".mp3",
".3gp",
".ogg",
".ogv",
".webm",
".m4a",
".flv",
".wmv",
".avi",
".swf",
".scss"
];
/**

@@ -30,10 +63,8 @@ * Remove Headers from a response

* @param {Object} opts
* @param {String} host
* @param {Number} port
* @param {Object} proxyHost
* @returns {String}
*/
function handleRedirect(url, opts, host, port) {
function handleRedirect(url, opts, proxyHost) {
var fullHost = opts.host + ":" + opts.port;
var proxyHost = host + ":" + port;

@@ -79,2 +110,28 @@ if (~url.indexOf(fullHost)) {

/**
* @param {Object} req
* @param {Array} [excludeList]
* @returns {Object}
*/
function handleIe(req) {
var ua = req.headers["user-agent"];
var match = /MSIE (\d)\.\d/.exec(ua);
if (match) {
if (parseInt(match[1], 10) < 9) {
var parsed = url.parse(req.url);
var ext = path.extname(parsed.pathname);
var excluded = excludeList.some(function (item) {
return item === ext;
});
if (!excluded) {
req.headers["accept"] = "text/html";
}
}
}
return req;
}
module.exports = {

@@ -84,3 +141,5 @@ rewriteLinks: rewriteLinks,

getProxyHost: getProxyHost,
getProxyUrl: getProxyUrl
getProxyUrl: getProxyUrl,
removeHeaders: removeHeaders,
handleIe: handleIe
};

4

package.json
{
"name": "foxy",
"version": "0.0.1",
"version": "0.1.0",
"description": "Proxy with response modding",

@@ -23,3 +23,3 @@ "main": "index.js",

"dependencies": {
"resp-modifier": "0.0.4",
"resp-modifier": "0.0.5",
"http-proxy": "^1.1.4"

@@ -26,0 +26,0 @@ },

@@ -5,2 +5,19 @@ ##Foxy [![Build Status](https://travis-ci.org/shakyShane/foxy.svg?branch=master)](https://travis-ci.org/shakyShane/foxy)

**In the near future, the api will be something like:**
```
var proxy = require("foxy");
// target // proxy url
proxy.createServer("http://localsite.dev", "http://localhost:5000");
```
Built-in middleware will re-write html on the fly to update any urls & there'll also be the option
for additional rules for the re-writing.
###Todo
- [x] websocket support
- [ ] accept a url for target
- [ ] test the shit out of the link re-writing
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