sub #215
@@ -1,8 +1,7 @@
|
|||||||
import { parseArgs } from "util";
|
import { parseArgs } from "util";
|
||||||
|
|
||||||
const serverUrl = `ws://localhost:1234?new`;
|
async function main({ url, domain }: { url: string; domain?: string }) {
|
||||||
|
const serverUrl = `ws://${domain || "localhost:1234"}?new`;
|
||||||
async function main({ url }: { url: string }) {
|
|
||||||
const socket = new WebSocket(serverUrl);
|
const socket = new WebSocket(serverUrl);
|
||||||
|
|
||||||
socket.addEventListener("message", (event) => {
|
socket.addEventListener("message", (event) => {
|
||||||
@@ -35,9 +34,13 @@ const { values } = parseArgs({
|
|||||||
required: true,
|
required: true,
|
||||||
short: "p",
|
short: "p",
|
||||||
},
|
},
|
||||||
|
domain: {
|
||||||
|
type: "string",
|
||||||
|
short: "d",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!values.port) throw "pass --port 3000";
|
if (!values.port) throw "pass --port 3000";
|
||||||
main({ url: `localhost:${values.port}` });
|
main({ url: `localhost:${values.port}`, domain: values.domain });
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ type Client = { id: string };
|
|||||||
|
|
||||||
const port = 1234;
|
const port = 1234;
|
||||||
const protocol = "http";
|
const protocol = "http";
|
||||||
|
const domain = Bun.env.DOMAIN || `localhost:${port}`;
|
||||||
|
console.log("domain:", domain);
|
||||||
const clients = new Map<string, ServerWebSocket<Client>>();
|
const clients = new Map<string, ServerWebSocket<Client>>();
|
||||||
const clientData = new Map<string, any>();
|
const clientData = new Map<string, any>();
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ serve<Client>({
|
|||||||
ws.send(
|
ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
id: ws.data.id,
|
id: ws.data.id,
|
||||||
url: `${protocol}://${ws.data.id}.localhost:${port}`,
|
url: `${protocol}://${ws.data.id}.${domain}`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user