Analytics: Ereignisse annehmen

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-01 09:27:22 +00:00
1 parent cd9aebe4b1
commit 3a48e6e677
6 files changed
+472 -4

No files matched your search

+8 -3
View File
@@ -1,5 +1,7 @@
import http from 'node:http';
import crypto from 'node:crypto';
import { createIngest } from './ingest.js';
import { createSalt } from './salt.js';
const MAX_ADMIN_BODY = 64 * 1024;
const SITE_KEY = /^[a-z0-9]{16,40}$/;
@@ -53,13 +55,16 @@ function validateSite(b) {
return { site: { projectId: b.projectId, domains: b.domains, active: b.active } };
}
function createHandlerServer({ config, db, role }) {
function createHandlerServer({ config, db, role, geo, salt, now }) {
const ingest = role === 'public' ? createIngest({ db, geo, salt: salt || createSalt({ now }), now }) : null;
return http.createServer(async (req, res) => {
try {
const url = new URL(req.url, 'http://x');
const parts = url.pathname.split('/').filter(Boolean);
const method = req.method;
if (ingest && await ingest(req, res, url.pathname)) return;
if (method === 'GET' && url.pathname === '/a/health') return send(res, 200, { ok: true });
if (role === 'admin' && parts[0] === 'a' && parts[1] === 'admin' && parts[2] === 'sites' && parts.length === 4
@@ -102,7 +107,7 @@ function createHandlerServer({ config, db, role }) {
});
}
// Öffentlicher Listener: nur /a/health (Erfassung folgt); Admin-Routen gibt es hier nicht.
export const createPublicServer = ({ config, db }) => createHandlerServer({ config, db, role: 'public' });
// Öffentlicher Listener: /a/health und /a/e (Erfassung); Admin-Routen gibt es hier nicht.
export const createPublicServer = ({ config, db, geo, salt, now }) => createHandlerServer({ config, db, role: 'public', geo, salt, now });
// Interner Listener für die Website-Verwaltung.
export const createAdminServer = ({ config, db }) => createHandlerServer({ config, db, role: 'admin' });