import { serve } from "https://deno.land/std/http/server.ts";
const body = new TextEncoder().encode("Hello World\n");
const s = serve({ port: 8000 });
console.log(s.url);
for await (const req of s) {
req.respond({ body });
}
two changes needed:
serve() needs to take { port: 8000 } instead of ":8000".s.url to return "http://localhost:8000/"That's my luck 馃槃 an API change few days after I presented the old API in my last talk.
After my first talk got recorded but before it got published, the deno run outdated my examples.
Both very good changes by the way 馃憤 it's just funny how my talks get outdated in a matter of days.
Why would s.url not return an instance of URL, which can be easily converted to a string, or otherwise used as seen fit?
Is there a plain to change for-await-of to a concurrent API?
@Fenzland No - I'm happy with for-await-of API. It is concurrent (as long as you call an async function without await).
@ry I did a PR #3278 to implement this (and PR #3279 that is the same but uses URL objects instead of strings as suggested by @kitsonk so that console.log(s.url.href) would have to be used).
The CI currently fails on some systems, sorry for that, I'll have to see why it fails on some systems and not others.
currently (Deno v1.0.0) url in ServerRequest returns just the part after hostname (pathname and search-params)
I think there should be a property like href to get the whole url string or an instance of URL. (2nd point in issue)
This would make it easier to access different parts of the url, hostname, pathname, params e.t.c
Most helpful comment
Why would
s.urlnot return an instance ofURL, which can be easily converted to a string, or otherwise used as seen fit?