|
|
@ -1,11 +1,39 @@ |
|
|
|
import type { APIRoute } from 'astro'; |
|
|
|
import type { APIRoute } from 'astro'; |
|
|
|
|
|
|
|
|
|
|
|
export const GET: APIRoute = async function ({ params, request, props }) { |
|
|
|
export const GET: APIRoute = async function ({ params, url, request, props }) { |
|
|
|
const { roadmapId } = params; |
|
|
|
const { roadmapId: fullRoadmapId } = params; |
|
|
|
|
|
|
|
if (!fullRoadmapId) { |
|
|
|
|
|
|
|
return new Response( |
|
|
|
|
|
|
|
JSON.stringify({ |
|
|
|
|
|
|
|
data: null, |
|
|
|
|
|
|
|
error: { |
|
|
|
|
|
|
|
message: 'Roadmap not found', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
status: 500, |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// to account for `roadmap/roadmap-beginner.json` files
|
|
|
|
|
|
|
|
const roadmapId = |
|
|
|
|
|
|
|
fullRoadmapId?.indexOf('-beginner') !== -1 |
|
|
|
|
|
|
|
? fullRoadmapId.replace('-beginner', '') |
|
|
|
|
|
|
|
: fullRoadmapId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fileName = |
|
|
|
|
|
|
|
roadmapId === fullRoadmapId |
|
|
|
|
|
|
|
? `${roadmapId}.json` |
|
|
|
|
|
|
|
: `${fullRoadmapId}.json`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(fileName); |
|
|
|
try { |
|
|
|
try { |
|
|
|
const roadmapJson = await import( |
|
|
|
const roadmapJson = await import( |
|
|
|
`../../data/roadmaps/${roadmapId}/${roadmapId}.json` |
|
|
|
`../../data/roadmaps/${roadmapId}/${fileName}` |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return new Response(JSON.stringify(roadmapJson), { |
|
|
|
return new Response(JSON.stringify(roadmapJson), { |
|
|
|