Initial commit: Tapalka monorepo (bot, front, strapi)
This commit is contained in:
51
CMyTapper/robucks-front/app/api/bot/[...path]/route.ts
Normal file
51
CMyTapper/robucks-front/app/api/bot/[...path]/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
const BOT_API_URL = process.env.BOT_API_INTERNAL || 'http://127.0.0.1:3001';
|
||||
|
||||
async function proxyRequest(req: NextRequest, params: { path: string[] }) {
|
||||
const path = params.path.join('/');
|
||||
const url = `${BOT_API_URL}/${path}`;
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
const fetchOptions: RequestInit = {
|
||||
method: req.method,
|
||||
headers,
|
||||
};
|
||||
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
||||
const body = await req.text();
|
||||
if (body) {
|
||||
fetchOptions.body = body;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await fetch(url, fetchOptions);
|
||||
const data = await response.json();
|
||||
|
||||
return NextResponse.json(data, { status: response.status });
|
||||
} catch (error) {
|
||||
console.error('Bot proxy error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Bot API unavailable' },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { path: string[] } }
|
||||
) {
|
||||
return proxyRequest(req, params);
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { path: string[] } }
|
||||
) {
|
||||
return proxyRequest(req, params);
|
||||
}
|
||||
Reference in New Issue
Block a user