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