From af371e030509a122a2c53658d370e9abc7fb83d0 Mon Sep 17 00:00:00 2001 From: qwerinope Date: Sat, 13 Sep 2025 23:58:41 +0200 Subject: [PATCH] root web now redirects to stream --- src/web/alerts/www/src/main.ts | 4 +++- src/web/index.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/web/alerts/www/src/main.ts b/src/web/alerts/www/src/main.ts index 0c054ea..76fb67a 100644 --- a/src/web/alerts/www/src/main.ts +++ b/src/web/alerts/www/src/main.ts @@ -3,7 +3,9 @@ import { alertEventData } from "web/alerts/types"; import alertManager from "./alertManager"; import "@fontsource/jersey-15"; -const socket = new WebSocket(`ws://${location.host}`); +const wsAddress = `ws${location.protocol === "https:" ? 's' : ''}://${location.host}`; + +const socket = new WebSocket(wsAddress); socket.onopen = () => { const instruction: serverInstruction = { diff --git a/src/web/index.ts b/src/web/index.ts index 1fe56ad..77f5b14 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -3,16 +3,14 @@ import chatWidget from "web/chatWidget/www/index.html"; import { getBadges, getExternalEmotes } from "web/chatWidget/widgetServerFunctions"; import alerts from "web/alerts/www/index.html"; import type { serverInstruction, serverNotificationEvent } from "web/serverTypes"; +import User from "user"; +import { streamerId } from "main"; const port = Number(process.env.WEB_PORT); if (isNaN(port)) { logger.enverr("WEB_PORT"); process.exit(1); }; export default Bun.serve({ port, - fetch(request, server) { - if (server.upgrade(request)) return; - return new Response('oops', { status: 500 }); - }, routes: { "/chat": chatWidget, "/chat/getBadges": getBadges, @@ -24,6 +22,11 @@ export default Bun.serve({ const file = Bun.file(`${import.meta.dir}/alerts/www/public/${target}`); if (!await file.exists()) return new Response(`${target} not found`, { status: 404 }); return new Response(file); + }, + "/": async (req, srv) => { + if (req.headers.get('Upgrade') === "websocket") { srv.upgrade(req); return; }; + const streamer = await User.initUserId(streamerId); + return Response.redirect(`https://twitch.tv/${streamer?.username}`); } }, websocket: {