Skip to content

Commit

Permalink
upgraded to bun serve, to counter cors origin issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-flip committed Sep 30, 2024
1 parent eb20332 commit ee2378b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
45 changes: 0 additions & 45 deletions index.html

This file was deleted.

23 changes: 23 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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)}`);
},
});

0 comments on commit ee2378b

Please sign in to comment.