mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-03 23:44:07 +00:00
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers. - Create configuration tests to validate loading of defaults and environment overrides. - Add tests for FEDL service to verify data handling and snapshot functionality. - Introduce GitHub service tests to check API data normalization and caching behavior. - Develop monitor service tests for network checks and uptime calculations. - Implement persistence tests to ensure database migrations are idempotent and data persists across restarts. - Add vault service tests for session management and brute-force protection mechanisms. - Include helper functions for test context creation and JSON response handling.
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
/*
|
|
* Privacy-friendly pageview beacon.
|
|
* - no cookies
|
|
* - no localStorage identifier
|
|
* - no query strings or fragments
|
|
* - never runs on private or operator pages
|
|
* The backend hashes the request IP with a daily rotating secret and discards it.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
if (window.__milesAnalyticsLoaded) return;
|
|
window.__milesAnalyticsLoaded = true;
|
|
|
|
var path = window.location.pathname || '/';
|
|
var skip = [
|
|
/^\/dashboard(?:\.html)?\/?$/,
|
|
/^\/vault\/?$/,
|
|
/^\/moon-vault(?:\.html)?$/,
|
|
/^\/games(?:\/|$)/,
|
|
/^\/api(?:\/|$)/,
|
|
/^\/404(?:\.html)?$/
|
|
];
|
|
if (skip.some(function (pattern) { return pattern.test(path); })) return;
|
|
|
|
var meta = document.querySelector('meta[name="miles-analytics-endpoint"]');
|
|
var endpoint = (meta && meta.getAttribute('content')) || '/api/analytics/hit';
|
|
|
|
var payload = {
|
|
path: path,
|
|
referrer: document.referrer || null
|
|
};
|
|
|
|
function send() {
|
|
try {
|
|
var body = JSON.stringify(payload);
|
|
fetch(endpoint, {
|
|
method: 'POST',
|
|
mode: 'cors',
|
|
credentials: 'same-origin',
|
|
cache: 'no-store',
|
|
keepalive: true,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: body
|
|
}).catch(function () {});
|
|
} catch (err) {
|
|
// Analytics must never break the page.
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'complete') send();
|
|
else window.addEventListener('load', send, { once: true });
|
|
})();
|