diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2020-02-24 22:10:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-24 08:10:00 -0500 |
commit | 162d66d23fe984d7ac0396faacb8800f19a719fd (patch) | |
tree | 4570440889605619da06b7f8c0a3a239c1047d70 /std/examples/chat | |
parent | 4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 (diff) |
fix: chat example's content-security-policy (#4091)
Diffstat (limited to 'std/examples/chat')
-rw-r--r-- | std/examples/chat/index.html | 7 | ||||
-rw-r--r-- | std/examples/chat/server.ts | 19 |
2 files changed, 20 insertions, 6 deletions
diff --git a/std/examples/chat/index.html b/std/examples/chat/index.html index b84a9f1dd..b26a4a15d 100644 --- a/std/examples/chat/index.html +++ b/std/examples/chat/index.html @@ -1,5 +1,6 @@ -<html> +<html lang="en"> <head> + <meta charset="UTF-8" /> <title>ws chat example</title> </head> <body> @@ -10,7 +11,7 @@ <button id="closeButton" disabled>close</button> </div> <div id="status"></div> - <ul id="timeline"></div> + <ul id="timeline"></ul> <script> let ws; function messageDom(msg) { @@ -35,7 +36,7 @@ } function connect() { if (ws) ws.close(); - ws = new WebSocket("ws://0.0.0.0:8080/ws"); + ws = new WebSocket(`ws://${location.host}/ws`); ws.addEventListener("open", () => { console.log("open", ws); applyState({connected: true}); 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({ |