Closed spidgorny closed 2 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 ;)
PUBLIC_URL works. But I was wondering if ctx.request.headers.get('host')
together with ctx.path
would do the trick?
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.
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, likehttp://localhost:4000/some/path?param1=2
.Is there a way?