chore: update README.md (#11633)

Updates "complex" example in the README.md, which used std/http
which will be phased out. Instead use newly stabilized Deno.serveHttp()
This commit is contained in:
Bartek Iwańczuk 2021-08-12 10:19:02 +02:00 committed by GitHub
parent b1799e6771
commit 3197cad0f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,11 +72,17 @@ deno run https://deno.land/std/examples/welcome.ts
Or a more complex one:
```ts
import { serve } from "https://deno.land/std/http/server.ts";
const s = serve({ port: 8000 });
const listener = Deno.listen({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
for await (const conn of listener) {
serve(conn);
}
async function serve(conn: Deno.Conn) {
for await (const { respondWith } of Deno.serveHttp(conn)) {
respondWith(new Response("Hello world"));
}
}
```