summaryrefslogtreecommitdiff
path: root/std/examples/chat/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/examples/chat/server.ts')
-rw-r--r--std/examples/chat/server.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/std/examples/chat/server.ts b/std/examples/chat/server.ts
index 7a5a3ea14..3c968e44e 100644
--- a/std/examples/chat/server.ts
+++ b/std/examples/chat/server.ts
@@ -36,12 +36,17 @@ listenAndServe({ port: 8080 }, async req => {
if (u.protocol.startsWith("http")) {
// server launched by deno run http(s)://.../server.ts,
fetch(u.href).then(resp => {
- resp.headers.set("content-type", "text/html");
- return req.respond(resp);
+ return req.respond({
+ status: resp.status,
+ headers: new Headers({
+ "content-type": "text/html"
+ }),
+ body: resp.body
+ });
});
} else {
// server launched by deno run ./server.ts
- const file = await Deno.open("./index.html");
+ const file = await Deno.open(u.pathname);
req.respond({
status: 200,
headers: new Headers({
@@ -51,6 +56,14 @@ listenAndServe({ port: 8080 }, async req => {
});
}
}
+ if (req.method === "GET" && req.url === "/favicon.ico") {
+ req.respond({
+ status: 302,
+ headers: new Headers({
+ location: "https://deno.land/favicon.ico"
+ })
+ });
+ }
if (req.method === "GET" && req.url === "/ws") {
if (acceptable(req)) {
acceptWebSocket({