Skip to content

Commit ccf29c1

Browse files
committed
Clean up browser chat demo snippet
1 parent 6401b96 commit ccf29c1

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

‎src/hosted/site.ts‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HOSTED_CAPTUN_HOSTNAME, isLoopbackHostname, RESERVED_TUNNEL_NAMES } from "../routing.js";
22
import { WWW_BROWSER_MODULE } from "./browser-module.generated.js";
33

4-
declare const createCaptunTunnel: typeof import("../index").createCaptunTunnel;
4+
declare const createCaptunTunnel: typeof import("../index.js").createCaptunTunnel;
55

66
declare function runtimeImport<T = unknown>(specifier: string): Promise<T>;
77

@@ -120,23 +120,21 @@ function chatRoomDemoSource() {
120120

121121
const messages = window.chatMessages.join("\n").replace(/[^\w\s-,.'"!?():]/g, "");
122122

123-
return new Response(
124-
String(`
125-
<script>
126-
let username = document.cookie.match(/username=([^;]+)/)?.[1];
127-
username ||= 'user' + Math.random().toString().slice(2, 8);
128-
document.cookie = 'username=' + username + '; Path=/; Secure';
129-
function send(form) {
130-
fetch('/', { method: 'POST', body: username + ': ' + form.m.value }).then(() => location.reload());
131-
}
132-
</script>
133-
<pre>${messages}</pre>
134-
<form onsubmit="send(this); return false">
135-
<input name="m" style="font-size:16px" autofocus><button>send</button>
136-
</form>
137-
`),
138-
{ headers: { "content-type": "text/html; charset=utf-8" } },
139-
);
123+
const html = `
124+
<script>
125+
let username = document.cookie.match(/username=([^;]+)/)?.[1];
126+
username ||= 'user' + Math.random().toString().slice(2, 8);
127+
document.cookie = 'username=' + username + '; Path=/; Secure';
128+
function send(form) {
129+
fetch('/', { method: 'POST', body: username + ': ' + form.msg.value }).then(() => location.reload());
130+
}
131+
</script>
132+
<pre>${messages}</pre>
133+
<form onsubmit="send(this); return false">
134+
<input name="msg" style="font-size:16px" autofocus><button>send</button>
135+
</form>
136+
`;
137+
return new Response(html, { headers: { "content-type": "text/html; charset=utf-8" } });
140138
},
141139
});
142140
}

0 commit comments

Comments
 (0)