diff --git a/ui/app/api/mirrors/cdc/route.ts b/ui/app/api/mirrors/cdc/route.ts index 7e66cda826..d83c8d398b 100644 --- a/ui/app/api/mirrors/cdc/route.ts +++ b/ui/app/api/mirrors/cdc/route.ts @@ -8,7 +8,7 @@ import { GetFlowHttpAddressFromEnv } from '@/rpc/http'; export async function POST(request: Request) { const body = await request.json(); const { config } = body; - console.log('/mirrors/cdc config: ', config); + const flowServiceAddr = GetFlowHttpAddressFromEnv(); const req: CreateCDCFlowRequest = { connectionConfigs: config, diff --git a/ui/app/api/mirrors/cdc/validate/route.ts b/ui/app/api/mirrors/cdc/validate/route.ts index a0be93bcbd..83107dcbc7 100644 --- a/ui/app/api/mirrors/cdc/validate/route.ts +++ b/ui/app/api/mirrors/cdc/validate/route.ts @@ -3,11 +3,11 @@ import { ValidateCDCMirrorResponse, } from '@/grpc_generated/route'; import { GetFlowHttpAddressFromEnv } from '@/rpc/http'; +import { NextRequest } from 'next/server'; -export async function POST(request: Request) { +export async function POST(request: NextRequest) { const body = await request.json(); const { config } = body; - console.log('/mirrors/cdc/validate config: ', config); const flowServiceAddr = GetFlowHttpAddressFromEnv(); const req: CreateCDCFlowRequest = { connectionConfigs: config, diff --git a/ui/app/api/mirrors/drop/route.ts b/ui/app/api/mirrors/drop/route.ts index a52e4b078d..205ab26fef 100644 --- a/ui/app/api/mirrors/drop/route.ts +++ b/ui/app/api/mirrors/drop/route.ts @@ -13,7 +13,7 @@ export async function POST(request: Request) { destinationPeer, removeFlowEntry: true, }; - console.log('/mirrors/drop: req:', req); + try { const dropStatus: ShutdownResponse = await fetch( `${flowServiceAddr}/v1/mirrors/drop`, diff --git a/ui/app/api/mirrors/qrep/route.ts b/ui/app/api/mirrors/qrep/route.ts index 63b8519fca..7febf60140 100644 --- a/ui/app/api/mirrors/qrep/route.ts +++ b/ui/app/api/mirrors/qrep/route.ts @@ -8,7 +8,7 @@ import { GetFlowHttpAddressFromEnv } from '@/rpc/http'; export async function POST(request: Request) { const body = await request.json(); const { config } = body; - console.log('/qrep/post config:', config); + const flowServiceAddr = GetFlowHttpAddressFromEnv(); const req: CreateQRepFlowRequest = { qrepConfig: config, diff --git a/ui/app/api/mirrors/state/route.ts b/ui/app/api/mirrors/state/route.ts index cbd0a9969d..5cb63ccfea 100644 --- a/ui/app/api/mirrors/state/route.ts +++ b/ui/app/api/mirrors/state/route.ts @@ -7,7 +7,6 @@ import { GetFlowHttpAddressFromEnv } from '@/rpc/http'; export async function POST(request: Request) { const body: MirrorStatusRequest = await request.json(); const flowServiceAddr = GetFlowHttpAddressFromEnv(); - console.log('/mirrors/state: req:', body); try { const res: MirrorStatusResponse = await fetch( `${flowServiceAddr}/v1/mirrors/${body.flowJobName}`, diff --git a/ui/app/api/mirrors/state_change/route.ts b/ui/app/api/mirrors/state_change/route.ts index bcc4dd2a8a..0d81b75e7d 100644 --- a/ui/app/api/mirrors/state_change/route.ts +++ b/ui/app/api/mirrors/state_change/route.ts @@ -4,7 +4,7 @@ import { GetFlowHttpAddressFromEnv } from '@/rpc/http'; export async function POST(request: Request) { const body = await request.json(); const flowServiceAddr = GetFlowHttpAddressFromEnv(); - console.log('/mirrors/state_change: req:', body); + try { const res: FlowStateChangeResponse = await fetch( `${flowServiceAddr}/v1/mirrors/state_change`, diff --git a/ui/app/api/peers/route.ts b/ui/app/api/peers/route.ts index 200aab3d79..5d43442bd8 100644 --- a/ui/app/api/peers/route.ts +++ b/ui/app/api/peers/route.ts @@ -72,7 +72,6 @@ export const dynamic = 'force-dynamic'; export async function POST(request: Request) { const body = await request.json(); - console.log('POST Validate Peer:', body); const { name, type, config, mode } = body; const flowServiceAddr = GetFlowHttpAddressFromEnv(); const peer = constructPeer(name, type, config); diff --git a/ui/middleware.ts b/ui/middleware.ts index 81dcfdbcf4..2030488536 100644 --- a/ui/middleware.ts +++ b/ui/middleware.ts @@ -1,13 +1,32 @@ import { Configuration } from '@/app/config/config'; import { withAuth } from 'next-auth/middleware'; -import { NextRequest, NextResponse } from 'next/server'; +import { NextRequest, NextResponse, userAgent } from 'next/server'; const authMiddleware = withAuth({}); export default async function middleware(req: NextRequest, resp: NextResponse) { + const accessLogUUID = crypto.randomUUID(); + const agent = userAgent(req); + const xForwardedFor = req.headers.get('x-forwarded-for'); + console.log( + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)})` + ); + if (Configuration.authentication.PEERDB_PASSWORD) { - return (authMiddleware as any)(req); + const authRes = await (authMiddleware as any)(req); + + const authResJson = NextResponse.next(); + console.log( + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${authResJson.status}` + ); + + return authRes; } + + const res = NextResponse.next(); + console.log( + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${res.status}` + ); } export const config = {