Giter VIP home page Giter VIP logo

cf-hub's Introduction

Cloudflare HUB

Small executable to run multiple HTTP servers on the same machine and be able to connect to each using a single port via Cloudflare.

Motivation

Cloudflare doesn't allow to specify origin server's port on a free tier, so when you run 2 HTTP servers. First on port 1234 and the second one on 5678 in order to connect to them, you have to specify the port in the URL. Just as follows: server1.com:1234 and server2.org:5678.

Solution

I think there might be a way to do that with Cloudflare redirects, but it didn't work for me.

This application will intercept every request intended for each defined domain and will redirect it to the specified server.

How to use

In Cloudflare panel for each domain:

  1. Go to Rules > Transform Rules.
  2. Click "Create rule" button.
  3. Set name as CF-HUB.
  4. In "If..." section select All incoming requests.
  5. In "Then..." Select Set static.
  6. Set "Header name" to node.
  7. Set "Value" to any name, but it's recommended to use your domain. For example: server1.com.

On the machine:

  1. Run the cf-hub to generate a config cf-hub-cfg.json.
  2. In the config file:
    • Set addr_server to the address on which the CF-HUB should operate. In most cases it should be your machine's WAN IP and port 80.
    • In nodes specify your domains and servers where JSON key is the "Value" you set before and the JSON value is IP and port of the application serving the website. For example: "server1.com": "127.0.0.1:1234".
  3. Run your servers.
  4. Run cf-hub.

Now when you visit each domain the request should be proxied via cloudflare to the CF-HUB. Cloudflare should modify the request, so it has additional header called node where the value is the string you've chosen before. Thanks to that the CF-HUB will be able to get the IP of the server this request was intended for and redirect it.

In case if something went wrong the Cloudflare will return Bad Gateway error page.

Disclaimer

  1. This is a simple program which shouldn't be used with high demanding platforms. It's intended for small hobby projects where the owner doesn't have enough funds to use different machines for each server.

  2. It doesn't support WebSockets.

  3. It's intended for Cloudflare domains, it won't work separately.

  4. There might be some unforeseen issues due to the nature of HTTP.

ToDo:

  • Better error handling.
  • Support WebSockets.
  • Fix issues with TLS.

cf-hub's People

Contributors

fssay avatar

Watchers

 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.