Git Product home page Git Product logo

subproxy's Introduction

Subdomain proxy using node-http-proxy.

This package lets you proxy websites using subdomains.
For example, if your domain is example.com, and you type www.google.com.example.com in the browser, you will see google's homepage.

Note that when running on localhost, you will probably need to modify your hosts file (instructions below).

Command-line usage

subproxy [options]

This starts a subproxy server using the specified command-line options:

-r host root (for example, localhost)
-p port to listen on (for example, 80)
-h this help message

Example

npm install subproxy
subproxy -r localhost -p 85

Next, in your hosts file, add the following line:

127.0.0.1       www.google.com.localhost	

Now, in your browser, navigate to the following url:

http://www.google.com.localhost:85

You should see google's webpage.

API usage

require('http-proxy').createServer(function (req, res, proxy) {
	require('subproxy').handleRequest(subProxyHost, port, req, res, proxy);
}).listen(port);

subproxy depends on node-http-proxy to proxy websites.

Updating your hosts file to run on localhost

If running this with localhost, you will have to update your hosts file.
Subdomains of localhost (such as www.google.com.localhost) won't be routed to localhost unless you update this file. Here are a couple tutorials I found which show you how to do this on different operating systems:

http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

http://boomshadow.net/tools-utilities/hosts-mod/

For example, if you want to proxy www.google.com, you will need to add this to your hosts file:

127.0.0.1       www.google.com.localhost	

Make sure you use spaces, not tabs, to separate the IP from the domain.

Public servers

If you host a subproxy on a public server, you will want to create a wildcard DNS record http://en.wikipedia.org/wiki/Wildcard_DNS_record. For example, if your domain is example.com, you would want to create a wildcard DNS record for *.example.com to point traffic to your IP address.

How it works

The subproxy command line starts a server using node-http-proxy. Then, it listens for requests.
It will look at the request, and pull out the subdomain (for example, given www.google.com.localhost, it will pull out www.google.com). It will then proxy the connection to the subdomain (so you would see www.google.com content in your browser). Additionally, it will replace references to the proxied domain (www.google.com) in the location header.
That way, you still see the full proxy url in the browser (www.google.com.localhost).

subproxy's People

Contributors

omphalos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.