@panomc/theme-core 1.0.0-dev.59 → 1.0.0-dev.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/kit/hooks-server.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panomc/theme-core",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.60",
|
|
4
4
|
"description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
|
|
5
5
|
"author": "PanoMC",
|
|
6
6
|
"license": "MIT",
|
package/src/kit/hooks-server.js
CHANGED
|
@@ -312,8 +312,34 @@ ${importMapEntries}
|
|
|
312
312
|
request.headers.set("Origin", API_URL);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
// The visit is recorded from SSR, so the backend's peer is this server: without the
|
|
316
|
+
// visitor's address every visit counted as 127.0.0.1 and the panel showed one visitor a
|
|
317
|
+
// day. Only this request carries it, so rate limits keep bucketing SSR as before.
|
|
318
|
+
if (new URL(request.url).pathname.endsWith("/api/visitorVisit")) {
|
|
319
|
+
const clientAddress = getVisitorAddress(event);
|
|
320
|
+
|
|
321
|
+
if (clientAddress) {
|
|
322
|
+
request.headers.set("X-Forwarded-For", clientAddress);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
315
326
|
return fetch(request);
|
|
316
327
|
}
|
|
317
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Cloudflare's header first (Pano Host sits behind it), then the first hop a reverse proxy
|
|
331
|
+
* declared (Pano's own UI proxy always fills one), then the socket peer.
|
|
332
|
+
*/
|
|
333
|
+
function getVisitorAddress(event) {
|
|
334
|
+
const headers = event.request.headers;
|
|
335
|
+
const forwardedFor = headers.get("x-forwarded-for")?.split(",")[0]?.trim();
|
|
336
|
+
|
|
337
|
+
try {
|
|
338
|
+
return headers.get("cf-connecting-ip")?.trim() || forwardedFor || event.getClientAddress();
|
|
339
|
+
} catch {
|
|
340
|
+
return forwardedFor || null;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
318
344
|
return { handle, handleError, handleFetch };
|
|
319
345
|
}
|