curveball / core

The Curveball framework is a TypeScript framework for node.js with support for modern HTTP features.
https://curveballjs.org/
MIT License
525 stars 7 forks source link

No way to get the complete request URL? #140

Closed spidgorny closed 2 years ago

spidgorny commented 4 years ago

ctx.request contains individual portions of the request URL - path, query. But I found no way to get the original request URL as a complete string, like http://localhost:4000/some/path?param1=2.

Is there a way?

evert commented 4 years ago

This doesn't exist right now. It's a bit of a tricky problem, because we can't know in every circumstance what the full url was. There's a lot of subtle edge-cases. Generally I recommend to people to use an environment variable like PUBLIC_URI in their application. Generally more reliable because you know if you have SSL termination or if you're behind a reverse proxy.

So this would then more be a fallback. I'm curious how other frameworks tackle this.

I'm not entirely against this, but a bit worried about future bug reports ;)

spidgorny commented 3 years ago

PUBLIC_URL works. But I was wondering if ctx.request.headers.get('host') together with ctx.path would do the trick?

evert commented 3 years ago

The Host header may be wrong depending on how a reverse proxy is configured, and this still doesn't answer the http vs https issue.

Maybe there's a good set of standard headers proxy send. I know Koa has a 'trustProxy' flag in some places, so probably worth doing some research.