import decrypt from "@moduletrace/datasquirel/dist/package-shared/functions/dsql/decrypt"; const AuthServerPort = 3177; type AdminPagesAuth = { date: number; user_id: number; url?: string; }; const server = Bun.serve({ port: AuthServerPort, hostname: "0.0.0.0", fetch(req) { console.log("req.headers", req.headers); try { const reqURL = new URL(req.url); console.log("reqURL", reqURL); if (reqURL.pathname !== "/") { return new Response("Auth Success!", { status: 200, }); } const host = req.headers.get("host"); const query = req.headers.get("x-original-uri"); const href = `https://${host}${query}`; const url = new URL(href); console.log("url", url); const key = url.searchParams.get("key"); const decryptedKey = JSON.parse( decrypt({ encryptedString: key! }), ) as AdminPagesAuth; const decrptedUrl = decryptedKey.url; console.log("decrptedUrl", decrptedUrl); if (!host || !decrptedUrl) { throw new Error(`Origin Not Found!`); } return new Response("Auth Success!", { status: 200, }); } catch (error: any) { console.log(`Auth Server Error => ${error.message}`); return new Response("Auth Failed!", { status: 401, }); } }, }); console.log(`Auth Server running at http://localhost:${server.port}/ ...`);