瀏覽代碼

used net/url insteadof testutils and created the Dockerfile

Mohamed Al Ashaal 6 年之前
父節點
當前提交
cf68a172f3
共有 4 個文件被更改,包括 50 次插入25 次删除
  1. 9 0
      Dockerfile
  2. 25 23
      README.md
  3. 9 0
      install.sh
  4. 7 2
      server.go

+ 9 - 0
Dockerfile

@@ -0,0 +1,9 @@
+FROM golang:alpine
+
+RUN apk update && apk add git
+
+RUN go get github.com/alash3al/httpsify
+
+ENTRYPOINT ["httpsify"]
+
+WORKDIR /root/

+ 25 - 23
README.md

@@ -1,29 +1,31 @@
-HTTPSify <small>v2</small>
+HTTPSify <small>v3</small>
 =============================
-A letsencrypt based reverse proxy to automatically handles ssl termination with no hassle .  
-It listens on `:443` by default **DON'T CHANGE IT** because letsencrypt uses that port to confirm ownership of your domains .  
+A `Let'sEncrypt` based reverse proxy, that will automatically generate &amp; renew valid `ssl` certs for your domains, it also enables the `http/2` protocol by default, and uses `roundrobin` as an algorithm to loadbalance the incoming requests between multiple `upstreams`
 
-Features
-=========
-* Auto `SSL Certs` generation and renewal .
-* Now you can specify custom backends for custom domains .
-* Now serves `websocket` based requestes easily with no problem .
+# Install
 
-Requirements
-=============
-* `Golang` >= 1.7
+### # Using Docker
+> Just run the following and then have fun !!
+```bash
+$ docker run -v $HOME:/root/ -p 443:443 alash3al/httpsify
+```
 
-Installation
-=============
-`go get github.com/alash3al/httpsify`
+### # Building from source
+> You must have the `Go` environment installed
+```bash
+$ go get -u github.com/alash3al/httpsify
+```
 
-Usage
-=============
-> run the following command and you will get some examples at the end .    
-
-`httpsify --help`
-
-Author
-========
-Mohammed Al Ashaal, a problem solver ;)
+### Configurations
+> Goto your `$HOME` Directory and edit the `hosts.json` to something like this
+```json
+{
+	"example1.com": ["http://localhost"],
+	"example2.com": ["http://localhost:8080", "http://localhost:8081"]
+}
+```
+> As you see, the configuration file accepts a `JSON` object/hashmap of `domain` -> `upstreams`,
+and yes, it can loadbalance the requests between multiple upstreams using `roundrobin` algorithm.
 
+> Also You don't need to restart the server to reload the configurations, because `httpsify` automatically watches the
+configurations file and reload it on any change.

+ 9 - 0
install.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+if [[ "$OSTYPE" == "linux-gnu" ]]; then
+	
+elif [[ "$OSTYPE" == "darwin"* ]]; then
+
+else
+    echo "Unsupported OS, try to build it from source"
+fi

+ 7 - 2
server.go

@@ -6,13 +6,14 @@ import (
 	"errors"
 	"io/ioutil"
 	"net/http"
+	"net/url"
 )
 
 import (
+	"github.com/fatih/color"
 	log "github.com/sirupsen/logrus"
 	"github.com/vulcand/oxy/forward"
 	"github.com/vulcand/oxy/roundrobin"
-	"github.com/vulcand/oxy/testutils"
 	"golang.org/x/crypto/acme/autocert"
 )
 
@@ -45,7 +46,11 @@ func ServeHTTP() http.Handler {
 			forwarder, _ := forward.New()
 			loadbalancer, _ := roundrobin.New(forwarder)
 			for _, upstream := range upstreams {
-				loadbalancer.UpsertServer(testutils.ParseURI(upstream))
+				if url, err := url.Parse(upstream); err == nil {
+					loadbalancer.UpsertServer(url)
+				} else {
+					colorize(color.FgRed, "⇛", err.Error())
+				}
 			}
 			loadbalancer.ServeHTTP(res, req)
 			return