From 1ffca3030cd37a937668c2289f274a901cd8a637 Mon Sep 17 00:00:00 2001 From: martbost Date: Sat, 10 Oct 2026 18:13:09 -0500 Subject: [PATCH] Games page: featured PolyWarriors listings come through a same-origin proxy (/api/public/pw-featured, 60 s cache); the page CSP blocked the direct call Co-Authored-By: Claude Fable 5.1 --- public/assets/games-page.js | 2 +- public/games.html | 2 +- server.js | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/assets/games-page.js b/public/assets/games-page.js index 4c36451..f863fdf 100644 --- a/public/assets/games-page.js +++ b/public/assets/games-page.js @@ -24,7 +24,7 @@ if (soon.length) S.innerHTML = '

Opening next

' + soon.map(card).join('') + '
'; }).catch(function () { document.getElementById('gEmpty').hidden = false; }); // featured warriors from the PolyWarriors market (2026-10-10): the rarest listings, with the forged art - fetch('https://www.polywarriors.com/api/public/featured').then(function (r) { return r.json(); }).then(function (d) { + fetch('/api/public/pw-featured').then(function (r) { return r.json(); }).then(function (d) { var f = (d && d.featured) || []; if (!f.length) return; var S = document.getElementById('gSoon'); var host = document.createElement('div'); host.id = 'gFeatured'; host.innerHTML = '

From the PolyWarriors market open the market

'; diff --git a/public/games.html b/public/games.html index 6267f6d..144fe11 100644 --- a/public/games.html +++ b/public/games.html @@ -78,6 +78,6 @@
Advertising services with a performance referral program. Not an investment product; no income guarantees.
- + diff --git a/server.js b/server.js index 89ee62e..118dadb 100644 --- a/server.js +++ b/server.js @@ -3425,6 +3425,11 @@ const server = http.createServer(async (req, res) => { } // -- cross-promo strip (2026-10-03): the list every game reads, and the counted hop between games // -- the public games page (2026-10-10, Marty: a page to send people): every game, open ones first, dated ones after + // featured PolyWarriors listings for the games page, fetched server-side (the page CSP allows no cross-origin calls), cached 60 s + if (p === '/api/public/pw-featured' && req.method === 'GET') { + const now = Date.now(); if (!global.__pwFeat || now - global.__pwFeat.at > 60000) { try { const r = await fetch(String(process.env.PW_URL || 'https://www.polywarriors.com').replace(/\/+$/, '') + '/api/public/featured', { signal: AbortSignal.timeout(6000) }); global.__pwFeat = { at: now, body: r.ok ? await r.json() : { featured: [] } }; } catch (e) { global.__pwFeat = { at: now, body: { featured: [] } }; } } + return json(res, 200, global.__pwFeat.body, { 'Cache-Control': 'public, max-age=60' }); + } if (p === '/api/public/games/all' && req.method === 'GET') { const sc = siteConfig(); const live = new Set(String(sc.gamesLive == null ? 'polhunter' : sc.gamesLive).split(',').map(x => x.trim().toLowerCase()).filter(Boolean)); const day = todayCT(), S = STRIP(); const lbl = (d, back) => { const t = new Date(d + 'T12:00:00Z'); if (back) t.setUTCDate(t.getUTCDate() - 1); return t.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' }); };