frontend: proxy /api/mcp/* → manar-mcp:8092 (exposes OAuth endpoints publicly)
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
const MCP_URL = process.env.MANAR_MCP_URL || 'http://manar-mcp:8092'
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: { path: string[] } }
|
||||||
|
) {
|
||||||
|
const path = params.path.join('/')
|
||||||
|
const search = req.nextUrl.search
|
||||||
|
const upstream = `${MCP_URL}/${path}${search}`
|
||||||
|
|
||||||
|
const resp = await fetch(upstream, {
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
redirect: 'manual',
|
||||||
|
})
|
||||||
|
|
||||||
|
if (resp.status >= 300 && resp.status < 400) {
|
||||||
|
return NextResponse.redirect(resp.headers.get('location') || '/', resp.status)
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await resp.text()
|
||||||
|
return new NextResponse(body, {
|
||||||
|
status: resp.status,
|
||||||
|
headers: { 'Content-Type': resp.headers.get('content-type') || 'application/json' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: { path: string[] } }
|
||||||
|
) {
|
||||||
|
const path = params.path.join('/')
|
||||||
|
const search = req.nextUrl.search
|
||||||
|
const upstream = `${MCP_URL}/${path}${search}`
|
||||||
|
const body = await req.text()
|
||||||
|
|
||||||
|
const resp = await fetch(upstream, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': req.headers.get('content-type') || 'application/json' },
|
||||||
|
body,
|
||||||
|
})
|
||||||
|
|
||||||
|
const respBody = await resp.text()
|
||||||
|
return new NextResponse(respBody, {
|
||||||
|
status: resp.status,
|
||||||
|
headers: { 'Content-Type': resp.headers.get('content-type') || 'application/json' },
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user