What is the best way to get the full url that Deno.serve() is running on?
If I have:
I know the url will be:
http://0.0.0.0:1993
. Is there something in the Deno.*
API that I can reference to get it though?4 Replies
yes, the
handler
(second parameter to Deno.serve()
) is a function that receives 2 parameters: request
and info
:
- serve
docs: https://docs.deno.com/api/deno/~/Deno.serve#function_serve_2
- ServeHandler
type definition: https://docs.deno.com/api/deno/~/Deno.ServeHandler
try this:
You can also get it from the request:
I'm on Widows where 0.0.0.0 === localhost.
If I then open 127.0.0.2 :1993 as expected:
Logging
info
on Windows returns an empty object?
With either console.log(info) or, console.info(info)?Thanks all! This is extremely helpful 🙂
I honestly just store these as environment variables since they differ per environment.