File size: 828 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ProjectSdk } from "@/utils/project-sdk"
import { isChartComponent } from "@/utils/shared"

interface Params {
  id: string
}

export async function GET(_req: Request, ctx: { params: Promise<Params> }) {
  const { id: exampleId } = await ctx.params

  const project = new ProjectSdk()
  const component = project.getComponentFromExample(exampleId)

  if (!component) {
    return new Response(JSON.stringify({ error: "Component not found" }), {
      status: 404,
      headers: {
        "Content-Type": "application/json",
      },
    })
  }

  const example = project.parseExample(
    component,
    isChartComponent(component)
      ? `charts/${exampleId}.tsx`
      : `${exampleId}.tsx`,
  )

  return new Response(JSON.stringify(example), {
    headers: {
      "Content-Type": "application/json",
    },
  })
}