github.com/maiha/http-gate

Quite simple http port forwarder

6 stars
0 dependents
License: MIT

Nothing has been indexed for 0.2.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  http-gate:
    github: maiha/http-gate
    version: ~> 0.2.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.2.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

http-gate Build Status

Quite simple http port forwarder.

Installation

Get x86_64 static binary from releases.

Usage

For example, listens '0.0.0.0:8080' and forwards by paths as follows.

0.0.0.0:8080
  /ch/* => 127.0.0.1:8123/*
  /*    => 127.0.0.1:9001/*
[front]
host = "0.0.0.0"
port = 8080

[[back]]
path = "/ch"
port = 8123
remove_path = true

[[back]]
path = "/"
port = 9001

[logger]
path = "STDOUT"
colorize = true
$ http-gate -c config.toml
I [11:43:30] F Add [Back#0] '/ch/' => 127.0.0.1:8123
I [11:43:30] F Add [Back#1] '/'    => 127.0.0.1:9001
I [11:43:30] F Listening on http://0.0.0.0:8080

Static File

[[back]]
type = "static"
path = "/public"
dir  = "/var/www/html"
remove_path = true
  • autoindex is not implemented yet.

Template File

This just embeds ENV and HTTP::Request::Headers variables into {{type:xxx}}. Here, type is one of env or req.

[[back]]
type = "template"
dir  = "/var/www/html"

For example, a html file

DIR: {{env:PWD}}
IP: {{req:X-FORWARDED-IP}}

will be converted to

DIR: /var/www
IP: 192.168.0.1
404

If the template file is not found, the filename specified by the 404 option is used as the template. If no option is provided, a 404 error will occur.

[[back]]
type  = "template"
dir   = "/var/www/html"
"404" = "404.html"
/var/www/html
  +-- 404.html

Since the request path is in req:PATH, you can easily create a redirect site by using the following static template file

Redirecting ... <a href="https://some.example.com{{req:PATH}}">some.example.com{{req:PATH}}</a>

Config

Show a sample of config.

$ http-gate --sample

Development

  • needs crystal-0.27.0
$ make

Contributing

  1. Fork it (https://github.com/maiha/http-gate/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer