-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded to bun serve, to counter cors origin issues
- Loading branch information
Showing
2 changed files
with
23 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}`); | ||
}, | ||
}); |