Skip to content

Commit

Permalink
fix: trim default port, log requests
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Jun 26, 2024
1 parent f3859c5 commit 004afef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
./ory proxy https://ory-network-httpbin-ijakee5waq-ez.a.run.app --quiet --rewrite-host &
npm run test
env:
ORY_API_KEY: placeholder
ORY_API_KEY: nokey
ORY_PROJECT_SLUG: affectionate-archimedes-s9mkjq77k0
ORY_CONSOLE_URL: https://console.staging.ory.dev
ORY_ORYAPIS_URL: https://staging.oryapis.dev
ORY_ORYAPIS_URL: https://projects.staging.oryapis.dev
ORY_RATE_LIMIT_HEADER: ${{ secrets.ORY_RATE_LIMIT_HEADER }}
26 changes: 23 additions & 3 deletions cmd/cloudx/proxy/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ func portFromEnv() int {
return port
}

func runReverseProxy(ctx context.Context, h *client.CommandHelper, stdErr io.Writer, conf *config, name string) error {
writer := herodot.NewJSONWriter(&errorLogger{Writer: stdErr})
mw := negroni.New()
type responseStatusCatcher struct {
http.ResponseWriter
status int
}

func (r *responseStatusCatcher) WriteHeader(status int) {
r.status = status
r.ResponseWriter.WriteHeader(status)
}

func runReverseProxy(ctx context.Context, h *client.CommandHelper, stdErr io.Writer, conf *config, name string) error {
signer, key, err := newJWTSigner()
if err != nil {
return err
Expand All @@ -125,6 +132,18 @@ func runReverseProxy(ctx context.Context, h *client.CommandHelper, stdErr io.Wri
slug = project.Slug
}
oryURL := client.CloudAPIsURL(slug)
oryURL.Host = strings.TrimSuffix(oryURL.Host, ":443")

writer := herodot.NewJSONWriter(&errorLogger{Writer: stdErr})
mw := negroni.New()

mw.UseFunc(func(w http.ResponseWriter, r *http.Request, n http.HandlerFunc) {
start := time.Now()
_, _ = fmt.Fprintf(stdErr, "%s [%s]\n", r.Method, r.URL)
statusCatcher := &responseStatusCatcher{ResponseWriter: w}
n(statusCatcher, r)
_, _ = fmt.Fprintf(stdErr, "=> %d %s [%s] took %s\n", statusCatcher.status, r.Method, r.URL, time.Since(start))
})

mw.UseFunc(func(w http.ResponseWriter, r *http.Request, n http.HandlerFunc) {
// Disable HSTS because it is very annoying to use on localhost.
Expand Down Expand Up @@ -254,6 +273,7 @@ and configure your SDKs to point to it, for example in JavaScript:
_, _ = fmt.Fprintf(stdErr, `To access your application via the Ory Proxy, open:
%s
`, conf.publicURL.String())
}

Expand Down

0 comments on commit 004afef

Please sign in to comment.