workign on canvas api requests

This commit is contained in:
2024-09-10 08:35:07 -06:00
parent 029e3ff7eb
commit f94dcca904
8 changed files with 121 additions and 210 deletions

View File

@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from "next/server";
import { axiosClient } from "@/services/axiosUtils";
export async function GET(
req: NextRequest,
{ params }: { params: { rest: string[] } }
) {
const { rest } = params;
const path = rest.join("/");
try {
const newUrl = `https://snow.instructure.com/api/v1/${path}`;
const response = await axiosClient.get(newUrl, {
headers: {
// Include other headers from the incoming request if needed:
// 'Content-Type': req.headers.get('content-type') || 'application/json',
"Content-Type": "application/json",
},
});
return NextResponse.json(response.data);
} catch (error: any) {
return new NextResponse(
JSON.stringify({ error: error.message || "Request failed" }),
{ status: error.response?.status || 500 }
);
}
}