feat: Add a websocket party (#152)

This adds functionality to connect to remote server thru the party
This commit is contained in:
Wanjohi
2025-01-05 23:45:41 +03:00
committed by GitHub
parent c15657a0d1
commit 56b877fa27
10 changed files with 384 additions and 252 deletions

View File

@@ -0,0 +1,21 @@
import type * as Party from "partykit/server";
export async function tryAuthentication(req: Party.Request, lobby: Party.Lobby) {
const authHeader = req.headers.get("authorization") ?? new URL(req.url).searchParams.get("authorization")
if (authHeader) {
const match = authHeader.match(/^Bearer (.+)$/);
if (!match || !match[1]) {
throw new Error("Bearer token not found or improperly formatted");
}
const bearerToken = match[1];
if (bearerToken !== lobby.env.AUTH_FINGERPRINT) {
throw new Error("Invalid authorization token");
}
return req// app.fetch(req as any, { room: this.room })
}
throw new Error("You are not authorized to be here")
}