Add SQLite visitor IP logging to /server_storage
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 1m9s

Log visitor IPs and paths to a local SQLite database via the existing
analytics API route, persisted at /server_storage/visitors.db in Docker
(falls back to ./visitors.db in dev).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Shivam Patel
2026-02-09 00:04:45 -05:00
parent 73eb9264df
commit 4a01928fe7
6 changed files with 481 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';
import { logVisit } from '@/lib/db';
const ANALYTICS_KEY = process.env.ANALYTICS_KEY || 'default-analytics-key';
@@ -19,6 +20,12 @@ export async function POST(req: Request) {
const forwarded = headers.get('x-forwarded-for');
const ip = forwarded ? forwarded.split(',')[0].trim() : 'unknown';
try {
logVisit(ip, body.path);
} catch (e) {
console.error('Failed to log visit to SQLite', e);
}
const adminUrl = process.env.ADMIN_DASH_URL || 'http://admin_dash:3000/api/track';
fetch(adminUrl, {