diff --git a/.github/workflows/fly.yml b/.github/workflows/fly.yml deleted file mode 100644 index 4a38ae95..00000000 --- a/.github/workflows/fly.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Deploy web proxy to Fly.io - -on: - push: - branches: [main] - paths: - - 'services/web-proxy/**' - -env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - -jobs: - deploy: - name: Deploy app - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: superfly/flyctl-actions/setup-flyctl@master - - run: (cd services/web-proxy && flyctl deploy) diff --git a/services/web-proxy/Dockerfile b/services/web-proxy/Dockerfile deleted file mode 100644 index d32c0ccc..00000000 --- a/services/web-proxy/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM alpine:latest as builder - -RUN apk add go - -WORKDIR /build -COPY . /build/ - -RUN go build . - -FROM alpine:latest - -COPY --from=builder /build/web-proxy /bin/web-proxy - -ENTRYPOINT [ "/bin/web-proxy" ] \ No newline at end of file diff --git a/services/web-proxy/fly.toml b/services/web-proxy/fly.toml deleted file mode 100644 index 4bb975d7..00000000 --- a/services/web-proxy/fly.toml +++ /dev/null @@ -1,28 +0,0 @@ -app = "pluralkit" -kill_signal = "SIGTERM" -kill_timeout = 5 - -[metrics] - port = 9091 - path = "/metrics" - -[deploy] - strategy = "bluegreen" - -[[services]] - internal_port = 8080 - protocol = "tcp" - - [services.concurrency] - hard_limit = 500 - soft_limit = 400 - type = "connections" - - [[services.ports]] - force_https = true - handlers = ["http"] - port = 80 - - [[services.ports]] - handlers = ["tls", "http"] - port = 443 \ No newline at end of file diff --git a/services/web-proxy/go.mod b/services/web-proxy/go.mod deleted file mode 100644 index e5074dcc..00000000 --- a/services/web-proxy/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module web-proxy - -go 1.19 diff --git a/services/web-proxy/main.go b/services/web-proxy/main.go deleted file mode 100644 index b8c5d971..00000000 --- a/services/web-proxy/main.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "context" - "log" - "net/http" - "net/http/httputil" - "net/url" - "time" -) - -func proxyTo(host string) *httputil.ReverseProxy { - rp := httputil.NewSingleHostReverseProxy(&url.URL{ - Scheme: "http", - Host: host, - RawQuery: "", - }) - rp.ModifyResponse = logTimeElapsed - return rp -} - -// todo: this shouldn't be in this repo -var remotes = map[string]*httputil.ReverseProxy{ - "api.pluralkit.me": proxyTo("pluralkit-api.flycast:5000"), - "dash.pluralkit.me": proxyTo("pluralkit-compute02._peer.internal:8080"), - "sentry.pluralkit.me": proxyTo("pluralkit-compute02._peer.internal:9000"), - "grafana.pluralkit.me": proxyTo("pluralkit-db1._peer.internal:3000"), -} - -type ProxyHandler struct{} - -func (p ProxyHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - remote, ok := remotes[r.Host] - if !ok { - // unknown domains redirect to landing page - http.Redirect(rw, r, "https://pluralkit.me", http.StatusFound) - return - } - - r.Header.Del("X-PluralKit-Client-IP") - r.Header.Set("X-PluralKit-Client-IP", r.Header.Get("Fly-Client-IP")) - - startTime := time.Now() - r = r.WithContext(context.WithValue(r.Context(), "req-time", startTime)) - - remote.ServeHTTP(rw, r) -} - -func logTimeElapsed(resp *http.Response) error { - r := resp.Request - - startTime := r.Context().Value("req-time").(time.Time) - - elapsed := time.Since(startTime) - - log.Printf("[%s] \"%s %s%s\" %d - %vms %s\n", r.Header.Get("Fly-Client-IP"), r.Method, r.Host, r.URL.Path, resp.StatusCode, elapsed.Milliseconds(), r.Header.Get("User-Agent")) - - return nil -} - -func main() { - http.ListenAndServe(":8080", ProxyHandler{}) -}