http-gate v0.3.3

Quite simple http port forwarder

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
Repository

http-gate

Owner
Statistic
  • 6
  • 1
  • 0
  • 0
  • 5
  • over 1 year ago
  • October 6, 2018
License

MIT License

Links
Synced at

Sat, 04 May 2024 04:52:31 GMT

Languages