MCPcopy Create free account
hub / github.com/codeaashu/claude-code / POST

Function POST

web/app/api/chat/route.ts:3–36  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

1import { NextRequest, NextResponse } from "next/server";
2
3export async function POST(req: NextRequest) {
4 try {
5 const body = await req.json();
6 const apiUrl = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3001";
7
8 const response = await fetch(`${apiUrl}/api/chat`, {
9 method: "POST",
10 headers: {
11 "Content-Type": "application/json",
12 ...(process.env.ANTHROPIC_API_KEY
13 ? { Authorization: `Bearer ${process.env.ANTHROPIC_API_KEY}` }
14 : {}),
15 },
16 body: JSON.stringify(body),
17 });
18
19 if (!response.ok) {
20 return NextResponse.json(
21 { error: "Backend request failed" },
22 { status: response.status }
23 );
24 }
25
26 // Stream the response through
27 return new NextResponse(response.body, {
28 headers: {
29 "Content-Type": response.headers.get("Content-Type") ?? "application/json",
30 },
31 });
32 } catch (error) {
33 console.error("Chat API error:", error);
34 return NextResponse.json({ error: "Internal server error" }, { status: 500 });
35 }
36}

Callers

nothing calls this directly

Calls 2

getMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected