Skip to content

Commit

Permalink
Add connected hosts path
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Sep 13, 2024
1 parent 262b692 commit db7b189
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const serve = (options: ServeOptions): Deno.HttpServer<Deno.NetAddr> => {
});
};

const CONNECTED_HOSTS_PATH = "/_hosts";
/**
* Creates a handler function for serving requests, with support for WebSocket connections
* and forwarding requests to registered domains.
Expand All @@ -80,6 +81,13 @@ export const serveHandler = (

return async (req) => {
const url = new URL(req.url);
if (url.pathname === CONNECTED_HOSTS_PATH) {
return new Response(JSON.stringify(hostToClientId), {
headers: {
"content-type": "application/json",
},
});
}
if (url.pathname === connectPath) {
const { socket, response } = Deno.upgradeWebSocket(req);
const clientVersion = url.searchParams.get(CLIENT_VERSION_QUERY_STRING);
Expand Down

0 comments on commit db7b189

Please sign in to comment.