chore: remove old web-proxy code
This is no longer used in our infra, and probably should never have been in this repo anyway Closes: PluralKit/PluralKit#511
This commit is contained in:
parent
6b14c50f09
commit
4d65237ee1
19
.github/workflows/fly.yml
vendored
19
.github/workflows/fly.yml
vendored
@ -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)
|
|
@ -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" ]
|
|
@ -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
|
|
@ -1,3 +0,0 @@
|
|||||||
module web-proxy
|
|
||||||
|
|
||||||
go 1.19
|
|
@ -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{})
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user