-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a4c399
commit 7ea04aa
Showing
4 changed files
with
104 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Language } from "@grida/builder-platform-types"; | ||
import { code } from "@grida/code"; | ||
import { NextResponse, type NextRequest } from "next/server"; | ||
|
||
export default async function GET(req: NextRequest) { | ||
// get the access token from the query string | ||
const figma = req.nextUrl.searchParams.get("figma") as string; | ||
const fpat = req.nextUrl.searchParams.get("fpat") as string; | ||
const fat = req.nextUrl.searchParams.get("fat") as string; | ||
|
||
if (!figma) { | ||
return new NextResponse("<h1>No figma file url is provided</h1>", { | ||
status: 400, | ||
}); | ||
} | ||
|
||
if (!fpat && !fat) { | ||
return new NextResponse("<h1>No figma access token is provided</h1>", { | ||
status: 400, | ||
}); | ||
} | ||
|
||
try { | ||
const gen = await code({ | ||
uri: figma as string, | ||
framework: { | ||
framework: "preview", | ||
imgage_alt: {}, | ||
language: Language.html, | ||
}, | ||
auth: { | ||
accessToken: fat as string, | ||
personalAccessToken: fpat as string, | ||
}, | ||
}); | ||
|
||
const { src } = gen!; | ||
|
||
return new NextResponse(src, { | ||
status: 200, | ||
headers: { | ||
"Content-Type": "text/html", | ||
}, | ||
}); | ||
|
||
} catch (e: any) { | ||
return new NextResponse(`<h1>${e?.message}</h1><pre>${e?.stack}</pre>`, { | ||
status: 500, | ||
headers: { | ||
"Content-Type": "text/html", | ||
}, | ||
}); | ||
} | ||
} |