From ee2378baf02ff6f473dc09a049d8ede8ea8b6eee Mon Sep 17 00:00:00 2001 From: Phil Date: Mon, 30 Sep 2024 21:41:34 +0200 Subject: [PATCH] upgraded to bun serve, to counter cors origin issues --- index.html | 45 --------------------------------------------- index.ts | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 45 deletions(-) delete mode 100644 index.html create mode 100644 index.ts diff --git a/index.html b/index.html deleted file mode 100644 index b23276a..0000000 --- a/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - Resonite World Link Utility - - -
JS disabled! Please enable it for this utility to work.
- - - \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..e211822 --- /dev/null +++ b/index.ts @@ -0,0 +1,23 @@ +import { serve } from "bun"; + +if (process.env.NODE_ENV === "development") + console.debug(`🚧 Running in debug mode!`); + +serve({ + port: process.env.PORT || 3000, + async fetch(req) { + // Extract sessionID from the current URL path + const url = new URL(req.url); + const sessionID = url.pathname.split("/")[1]; + if (!sessionID) return new Response(`No sessionID provided! Example: "${`${url}`}S-U-h33tology:fitness"`, { status: 400 }); + // send API request to Resonite to get lnl-net link + const sessionDetailsRaw = await fetch(`${process.env.RESONITE_API_ENDPOINT}/${sessionID}`); + const sessionDetails = await sessionDetailsRaw.json(); + + // verify the existence and redirect to steam + if (sessionDetails.status) return new Response(sessionDetails.title, { status: sessionDetails.status }); + const lnl = sessionDetails.sessionURLs[0]; + if (!lnl) return new Response(`Session "${sessionID}" doesn\'t have a lnl-net link.`, { status: 404 }); + return Response.redirect(`steam://rungameid/2519830//-Open ${encodeURIComponent(lnl)}`); + }, +});