All checks were successful
Deploy / deploy (push) Successful in 3m10s
Tool endpoints (events, notes, transport, weather) call other /api/* routes via loopback (http://localhost:3000). Those routes are middleware-protected — cookie-less loopbacks were getting 401, which surfaced to the voice agent as get_today_events → tool_http_502. Add internal header bypass: middleware lets the request through when x-voice-internal matches VOICE_API_KEY. Only our own tool endpoints use this header, from inside the same container, so the blast radius is limited to loopback traffic. - middleware.ts: check x-voice-internal before cookie - lib/voice-tools.ts: internalHeaders() helper - app/api/voice/tools/{weather,transport,events,notes}: use it
30 lines
987 B
TypeScript
30 lines
987 B
TypeScript
export const dynamic = 'force-dynamic'
|
|
export const runtime = 'nodejs'
|
|
|
|
import { NextResponse } from 'next/server'
|
|
import { isBearerAuthorized, unauthorized, internalHeaders } from '@/lib/voice-tools'
|
|
|
|
export async function GET(req: Request) {
|
|
if (!isBearerAuthorized(req)) return unauthorized()
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
const range = searchParams.get('range') || 'today' // today | week
|
|
|
|
const baseUrl = `http://localhost:${process.env.PORT || '3000'}`
|
|
const r = await fetch(`${baseUrl}/api/calendar?range=${encodeURIComponent(range)}`, {
|
|
cache: 'no-store',
|
|
headers: internalHeaders(),
|
|
}).catch(() => null)
|
|
|
|
if (!r || !r.ok) return NextResponse.json({ events: [], error: 'unreachable' }, { status: 502 })
|
|
const j = await r.json()
|
|
const events = (j.events || []).map((e: any) => ({
|
|
title: e.title,
|
|
start: e.start,
|
|
end: e.end,
|
|
all_day: e.allDay,
|
|
owner: e.ownerName || e.owner,
|
|
}))
|
|
return NextResponse.json({ events })
|
|
}
|