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) => { |
try { |
||||||
const bestPracticeId = filePath.split('/').pop()?.replace('.json', ''); |
const roadmapJson = await import( |
||||||
const bestPracticeJson = bestPracticeJsons[filePath] as Record<string, any>; |
`../../../data/best-practices/${bestPracticeId}/${bestPracticeId}.json` |
||||||
|
); |
||||||
|
|
||||||
return { |
return new Response(JSON.stringify(roadmapJson), { |
||||||
params: { |
status: 200, |
||||||
bestPracticeId, |
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