chore: initial commit with Phase 0 setup
This commit is contained in:
26
packages/mcp-server/src/proxy.ts
Normal file
26
packages/mcp-server/src/proxy.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export async function proxyToBackend(
|
||||
endpoint: string,
|
||||
payload: any,
|
||||
baseUrl?: string,
|
||||
apiKey?: string
|
||||
) {
|
||||
if (!baseUrl) throw new Error("API_BASE_URL is not configured.");
|
||||
|
||||
const url = `${baseUrl.replace(/\/$/, "")}${endpoint}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${apiKey || ""}`,
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Backend error (${response.status}): ${text}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
Reference in New Issue
Block a user