Skip to content

Commit 15424f0

Browse files
committed
adding analytics
1 parent 9a8bd75 commit 15424f0

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

app/analytics/page.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ interface AnalyticsData {
5757
statusCodeDistribution: Array<{ code: number; count: number }>;
5858
} | null;
5959
security: {
60-
events: Array<any>;
60+
events: Array<{
61+
timestamp: Date;
62+
type: string;
63+
ipAddress: string;
64+
userAgent: string;
65+
clientId?: string;
66+
details: string;
67+
}>;
6168
eventCount: number;
6269
};
6370
};

app/mcp/[transport]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createMcpHandler } from "@vercel/mcp-adapter";
22
import { z } from "zod";
33
import { prisma } from '@/app/prisma';
44
import { NextRequest } from 'next/server';
5-
import { analyticsCollector, getClientIP, extractClientInfo } from '@/lib/analytics';
5+
import { analyticsCollector, getClientIP } from '@/lib/analytics';
66

77
// Authentication helper
88
async function authenticateRequest(request: NextRequest) {

generated/prisma/edge.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/prisma/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const config = {
238238
"db"
239239
],
240240
"activeProvider": "postgresql",
241+
"postinstall": false,
241242
"inlineDatasources": {
242243
"db": {
243244
"url": {

lib/analytics.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,15 @@ export async function getLocationFromIP(ip: string) {
217217
try {
218218
// Using a free IP geolocation service (ip-api.com)
219219
// In production, consider using a paid service for better reliability
220+
const controller = new AbortController();
221+
const timeoutId = setTimeout(() => controller.abort(), 2000); // 2 second timeout
222+
220223
const response = await fetch(`http://ip-api.com/json/${ip}?fields=country,city`, {
221-
timeout: 2000 // 2 second timeout
224+
signal: controller.signal
222225
});
223226

227+
clearTimeout(timeoutId);
228+
224229
if (response.ok) {
225230
const data = await response.json();
226231
return {
@@ -256,4 +261,4 @@ export function getClientIP(request: NextRequest): string {
256261
return '127.0.0.1';
257262
}
258263

259-
export { RequestAnalytics, SecurityEvent };
264+
export type { RequestAnalytics, SecurityEvent };

0 commit comments

Comments
 (0)