diff --git a/server/index.js b/server/index.js index 973cc95..1f5e355 100644 --- a/server/index.js +++ b/server/index.js @@ -19,8 +19,43 @@ app.get("/health", (req, res) => { res.json({ status: "ok" }); }); -// Proxy for Steam API -// Note: Uberspace removes /api prefix, so we get / here +// Steam API refresh endpoint +app.post("/steam/refresh", async (req, res) => { + const { apiKey, steamId } = req.body; + + console.log(`Steam refresh for user: ${steamId}`); + + if (!apiKey || !steamId) { + return res.status(400).json({ + error: "Missing required fields: apiKey and steamId", + }); + } + + try { + // Call Steam Web API + const steamUrl = `https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key=${apiKey}&steamid=${steamId}&include_appinfo=1&include_played_free_games=1&format=json`; + + const response = await fetch(steamUrl); + + if (!response.ok) { + return res.status(response.status).json({ + error: "Steam API error", + message: response.statusText, + }); + } + + const data = await response.json(); + res.json(data); + } catch (error) { + console.error("Steam API error:", error); + res.status(500).json({ + error: "Failed to fetch games", + message: error.message, + }); + } +}); + +// Fallback proxy for other Steam API calls app.all("/*", async (req, res) => { const path = req.url; const steamUrl = `https://store.steampowered.com${path}`;