parent
7c1c295c63
commit
4fcf1f6d50
6 changed files with 92 additions and 69 deletions
@ -1,33 +1,33 @@ |
|||||||
import type { APIRoute } from 'astro'; |
import type { APIRoute } from 'astro'; |
||||||
|
|
||||||
export async function getStaticPaths() { |
export const GET: APIRoute = async function ({ params, request, props }) { |
||||||
const bestPracticeJsons = await import.meta.glob( |
const { bestPracticeId } = params; |
||||||
'/src/data/best-practices/**/*.json', |
|
||||||
{ |
|
||||||
eager: true, |
|
||||||
} |
|
||||||
); |
|
||||||
|
|
||||||
return Object.keys(bestPracticeJsons).map((filePath) => { |
|
||||||
const bestPracticeId = filePath.split('/').pop()?.replace('.json', ''); |
|
||||||
const bestPracticeJson = bestPracticeJsons[filePath] as Record<string, any>; |
|
||||||
|
|
||||||
return { |
try { |
||||||
params: { |
const roadmapJson = await import( |
||||||
bestPracticeId, |
`../../../data/best-practices/${bestPracticeId}/${bestPracticeId}.json` |
||||||
}, |
); |
||||||
props: { |
|
||||||
bestPracticeJson: bestPracticeJson?.default, |
|
||||||
}, |
|
||||||
}; |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
export const GET: APIRoute = async function ({ params, request, props }) { |
return new Response(JSON.stringify(roadmapJson), { |
||||||
return new Response(JSON.stringify(props.bestPracticeJson), { |
|
||||||
status: 200, |
status: 200, |
||||||
headers: { |
headers: { |
||||||
'content-type': 'application/json', |
'Content-Type': 'application/json', |
||||||
}, |
}, |
||||||
}); |
}); |
||||||
|
} catch (error) { |
||||||
|
return new Response( |
||||||
|
JSON.stringify({ |
||||||
|
data: null, |
||||||
|
error: { |
||||||
|
message: 'Best Practices not found', |
||||||
|
}, |
||||||
|
}), |
||||||
|
{ |
||||||
|
status: 500, |
||||||
|
headers: { |
||||||
|
'Content-Type': 'application/json', |
||||||
|
}, |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
}; |
}; |
||||||
|
Loading…
Reference in new issue