Dev console
This commit is contained in:
parent
882ff7696a
commit
130bed1d1f
5 changed files with 4790 additions and 60 deletions
33
app/api/dev/proxy/route.ts
Normal file
33
app/api/dev/proxy/route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const token = req.cookies.get("token")?.value;
|
||||
if (!token) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { method, url, body } = (await req.json()) as {
|
||||
method: string;
|
||||
url: string;
|
||||
body?: unknown;
|
||||
};
|
||||
|
||||
const targetUrl = url.startsWith("http")
|
||||
? url
|
||||
: `http://localhost:3001${url.startsWith("/") ? url : `/${url}`}`;
|
||||
|
||||
const res = await fetch(targetUrl, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
||||
},
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
|
||||
const text = await res.text();
|
||||
return new NextResponse(text, {
|
||||
status: res.status,
|
||||
headers: { "Content-Type": res.headers.get("Content-Type") ?? "text/plain" },
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue