diff --git a/backend/analytics-db.js b/backend/analytics-db.js index 8465f78..d8a36df 100644 --- a/backend/analytics-db.js +++ b/backend/analytics-db.js @@ -13,7 +13,11 @@ function loadDB() { } function saveDB(data) { - writeFileSync(DB_FILE, JSON.stringify(data, null, 2)); + try { + writeFileSync(DB_FILE, JSON.stringify(data, null, 2)); + } catch (e) { + console.error('Analytics DB Schreibfehler:', e.message); + } } let db = loadDB(); diff --git a/backend/server.js b/backend/server.js index 8eaba26..921e3e1 100644 --- a/backend/server.js +++ b/backend/server.js @@ -20,17 +20,19 @@ app.use((req, res, next) => { if (req.method === 'OPTIONS' || !req.path.startsWith('/api/')) return next(); if (req.path.startsWith('/api/analytics')) return next(); - let userId = null; - const authHeader = req.headers.authorization; - if (authHeader && authHeader.startsWith('Bearer ')) { - try { - const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET); - const user = getUserByUsername(decoded.username); - if (user) userId = user.id; - } catch {} - } + try { + let userId = null; + const authHeader = req.headers.authorization; + if (authHeader && authHeader.startsWith('Bearer ')) { + try { + const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET); + const user = getUserByUsername(decoded.username); + if (user) userId = user.id; + } catch {} + } + trackEvent('page_view', userId, { path: req.path, method: req.method }); + } catch {} - trackEvent('page_view', userId, { path: req.path, method: req.method }); next(); }); diff --git a/backend/services/instagram.js b/backend/services/instagram.js index cb88455..f494f06 100644 --- a/backend/services/instagram.js +++ b/backend/services/instagram.js @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - const INSTAGRAM_TOKEN = process.env.INSTAGRAM_TOKEN; export async function getInstagramData(url) { diff --git a/backend/services/tiktok.js b/backend/services/tiktok.js index b5800ed..3564f28 100644 --- a/backend/services/tiktok.js +++ b/backend/services/tiktok.js @@ -1,5 +1,3 @@ -import fetch from 'node-fetch'; - export async function getTikTokData(url) { const oembedUrl = `https://www.tiktok.com/oembed?url=${encodeURIComponent(url)}`; const response = await fetch(oembedUrl);