From 5e13c655f976eb4b597b0f8974298e8f186f8c48 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Mon, 23 Dec 2019 23:35:19 +0200 Subject: [PATCH 01/11] updated README --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 19e3631..33e7a10 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ HTTPSify ======== A `Let'sEncrypt` based reverse proxy, that will automatically generate & 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`, as well as redirecting the traffic from `http` traffic to `https` just if you enabled the flag `--redirect`. -NOTES -======= -> HTTPSify only supports `http-01` challenge because [Let's Encrypt disables TLS-SNI-01 validation](http://www.zdnet.com/article/lets-encrypt-disables-tls-sni-01-validation/) # Quick Start From 975b5b1d19f068512cff33627257e9bbcc7c73c2 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Fri, 27 Dec 2019 14:48:00 +0200 Subject: [PATCH 02/11] added gitignore and updated go mod --- .gitignore | 1 + go.mod | 1 + go.sum | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/go.mod b/go.mod index ab1374e..326bd29 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,6 @@ require ( github.com/labstack/echo v3.3.10+incompatible github.com/labstack/echo/v4 v4.1.11 github.com/mitchellh/go-homedir v1.1.0 + github.com/mitchellh/gox v1.0.1 // indirect golang.org/x/crypto v0.0.0-20191219195013-becbf705a915 ) diff --git a/go.sum b/go.sum index c9068a1..8f488d1 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= +github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/echo/v4 v4.1.11 h1:z0BZoArY4FqdpUEl+wlHp4hnr/oSR6MTmQmv8OHSoww= @@ -16,6 +18,10 @@ github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= +github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= From 6629d906683487ad4bb497120a15a8a54f9a1cda Mon Sep 17 00:00:00 2001 From: Jon Penn Date: Sat, 28 Aug 2021 16:18:35 -0500 Subject: [PATCH 03/11] allow alternate ACME urls --- main.go | 5 +++++ vars.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/main.go b/main.go index 62de27b..6893d08 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + "golang.org/x/crypto/acme" "golang.org/x/crypto/acme/autocert" ) @@ -13,6 +14,10 @@ func main() { e.HideBanner = true e.AutoTLSManager.HostPolicy = autocert.HostWhitelist(getAvailableHosts()...) e.AutoTLSManager.Cache = autocert.DirCache(*flagAutocertCacheDir) + e.AutoTLSManager.Client = &acme.Client{ + DirectoryURL: *flagACMEDirectory, + UserAgent: "https://github.com/alash3al/httpsify", + } e.Use(middleware.HTTPSRedirect()) e.Use(middleware.Logger()) diff --git a/vars.go b/vars.go index c9d1e4f..70406e4 100644 --- a/vars.go +++ b/vars.go @@ -6,6 +6,7 @@ import ( "sync/atomic" "github.com/mitchellh/go-homedir" + "golang.org/x/crypto/acme/autocert" ) var ( @@ -18,5 +19,6 @@ var ( flagHTTPAddr = flag.String("http", ":80", "the port to listen for http requests on, it is recommended to leave it as is") flagAutocertCacheDir = flag.String("certs", path.Join(homeDir, ".httpsify/certs"), "the certs directory") flagHostsFile = flag.String("hosts", path.Join(homeDir, ".httpsify/hosts.json"), "the file containing hosts mappings to upstreams") + flagACMEDirectory = flag.String("acme-directory", autocert.DefaultACMEDirectory, "the server to request certificates from") flagSendXSecuredBy = flag.Bool("x-secured-by", true, "whether to enable x-secured-by header or not") ) From 160011c5ce0e02c8772056940a8868bf65c05795 Mon Sep 17 00:00:00 2001 From: Jon Penn Date: Sat, 28 Aug 2021 19:15:21 -0500 Subject: [PATCH 04/11] remove unnecessary select --- hosts.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hosts.go b/hosts.go index 2dc72b8..ad82dd2 100644 --- a/hosts.go +++ b/hosts.go @@ -76,10 +76,8 @@ func watchHostsChanges(filename string, fn func()) error { watcher.Add(filename) for { - select { - case <-watcher.Events: - fn() - } + <-watcher.Events + fn() } } From 6408819e17309659eaa00cf9a6d1dfaccdd6f3eb Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 13:21:44 +0300 Subject: [PATCH 05/11] added github builder action go mod tidy --- .github/workflows/builder.yaml | 69 ++++++++++++++++++++++++++++++++++ .idea/.gitignore | 8 ++++ .idea/httpsify.iml | 9 +++++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ go.mod | 2 - go.sum | 14 +++---- 7 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/builder.yaml create mode 100644 .idea/.gitignore create mode 100644 .idea/httpsify.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml new file mode 100644 index 0000000..28b928a --- /dev/null +++ b/.github/workflows/builder.yaml @@ -0,0 +1,69 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Build & Release + +on: + release: + types: [created] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: alash3al/httpsify + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Github Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + file: Dockerfile + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max + go: + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + goos: [linux, windows, darwin] + goarch: ["386", amd64, arm, arm64] + steps: + - uses: actions/checkout@v3 + - uses: wangyoucao577/go-release-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: "https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz" + project_path: "." + binary_name: "httpsify" + ldflags: "-s -w" \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/httpsify.iml b/.idea/httpsify.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/httpsify.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7aa24f9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/go.mod b/go.mod index 326bd29..4be4675 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,7 @@ go 1.13 require ( github.com/fsnotify/fsnotify v1.4.7 - github.com/labstack/echo v3.3.10+incompatible github.com/labstack/echo/v4 v4.1.11 github.com/mitchellh/go-homedir v1.1.0 - github.com/mitchellh/gox v1.0.1 // indirect golang.org/x/crypto v0.0.0-20191219195013-becbf705a915 ) diff --git a/go.sum b/go.sum index 8f488d1..2064a6f 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,9 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= -github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= -github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/echo/v4 v4.1.11 h1:z0BZoArY4FqdpUEl+wlHp4hnr/oSR6MTmQmv8OHSoww= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= @@ -18,19 +15,16 @@ github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= -github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= -github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191219195013-becbf705a915 h1:aJ0ex187qoXrJHPo8ZasVTASQB7llQP6YeNzgDALPRk= golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -43,5 +37,7 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 1f9c22232dff80a8240a3f9da61755507647c35e Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 13:29:26 +0300 Subject: [PATCH 06/11] updated Dockerfile --- Dockerfile | 25 ++++++++++++++++++------- README.md | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b7e030..db756c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,21 @@ -FROM golang:alpine AS builder +FROM golang:1.18-alpine As builder -RUN apk add --no-cache git && CGO_ENABLED=0 GOOS=linux go get github.com/alash3al/httpsify -RUN apk add -U --no-cache ca-certificates +WORKDIR /httpsify/ -FROM scratch -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /go/bin/httpsify /go/bin/httpsify +RUN apk update && apk add git -ENTRYPOINT ["/go/bin/httpsify"] +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /usr/bin/httpsify ./cmd/ + +FROM alpine + +WORKDIR /httpsify/ + +COPY --from=builder /usr/bin/httpsify /usr/bin/httpsify + +CMD httpsify \ No newline at end of file diff --git a/README.md b/README.md index 33e7a10..bd000ff 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A `Let'sEncrypt` based reverse proxy, that will automatically generate & ren ### # Using Docker > Just run the following and then have fun !! ```bash -$ docker run --network host -v ~/.httpsify:/.httpsify -p 443:443 alash3al/httpsify +$ docker run --network host -v ~/.httpsify:/.httpsify -p 443:443 ghcr.io/alash3al/httpsify ``` ## # From Binaries From a4b7b73e1a73dc5cdcd6a1217279f45f5238f22e Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 13:33:29 +0300 Subject: [PATCH 07/11] fixed Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index db756c0..f890a8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /usr/bin/httpsify ./cmd/ +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /usr/bin/httpsify . FROM alpine From 9f6100514b4b05e12819fe68a1658d67416a79cd Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 13:36:36 +0300 Subject: [PATCH 08/11] updated builder.yaml --- .github/workflows/builder.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml index 28b928a..43a205a 100644 --- a/.github/workflows/builder.yaml +++ b/.github/workflows/builder.yaml @@ -55,7 +55,7 @@ jobs: strategy: matrix: goos: [linux, windows, darwin] - goarch: ["386", amd64, arm, arm64] + goarch: [amd64, arm64, arm64] steps: - uses: actions/checkout@v3 - uses: wangyoucao577/go-release-action@v1 From cbd821be461b98e253696c71c654a9bccf960e47 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 15:34:06 +0300 Subject: [PATCH 09/11] use http-001 challenge --- main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 6893d08..331c2ea 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,8 @@ func main() { UserAgent: "https://github.com/alash3al/httpsify", } + httpChallengeHandler := e.AutoTLSManager.HTTPHandler(nil) + e.Use(middleware.HTTPSRedirect()) e.Use(middleware.Logger()) e.Use(middleware.Recover()) @@ -27,12 +29,22 @@ func main() { if *flagSendXSecuredBy { c.Response().Header().Set("X-Secured-By", "https://github.com/alash3al/httpsify") } - return next(c) + + if !c.IsTLS() { + return echo.WrapHandler(httpChallengeHandler)(c) + } + + hosts := hosts.Load().(map[string]*echo.Echo) + host := hosts[c.Request().Host] + + if host == nil { + return echo.ErrNotFound + } + + return echo.WrapHandler(host)(c) } }) - e.Any("/*", handler) - errChan := make(chan error) go (func() { From adbf9a5bc3508faefb58f390dd291dca56f4fb93 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 15:41:14 +0300 Subject: [PATCH 10/11] updated main.go --- main.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 331c2ea..aee5fc8 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "net/http" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -19,9 +20,6 @@ func main() { UserAgent: "https://github.com/alash3al/httpsify", } - httpChallengeHandler := e.AutoTLSManager.HTTPHandler(nil) - - e.Use(middleware.HTTPSRedirect()) e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.Use(func(next echo.HandlerFunc) echo.HandlerFunc { @@ -30,10 +28,6 @@ func main() { c.Response().Header().Set("X-Secured-By", "https://github.com/alash3al/httpsify") } - if !c.IsTLS() { - return echo.WrapHandler(httpChallengeHandler)(c) - } - hosts := hosts.Load().(map[string]*echo.Echo) host := hosts[c.Request().Host] @@ -48,7 +42,7 @@ func main() { errChan := make(chan error) go (func() { - errChan <- e.Start(*flagHTTPAddr) + errChan <- http.ListenAndServe(*flagHTTPAddr, e.AutoTLSManager.HTTPHandler(nil)) })() go (func() { From 6bd5cf60b02853ac0c8bffe1233695fd83f6ef62 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Tue, 20 Jun 2023 15:47:35 +0300 Subject: [PATCH 11/11] updated README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd000ff..e12b1a8 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,14 @@ $ go get -u github.com/alash3al/httpsify > Goto your `$HOME` Directory and edit the `hosts.json` to something like this ```json { - "example1.com": ["http://localhost:9080"], - "example2.com": ["http://localhost:8080", "http://localhost:8081"] + "example1.com": ["localhost:9080"], + "example2.com": ["localhost:8080", "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. +and yes, it can load-balance 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 +> 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. # License