Skip to content

Commit

Permalink
πŸ› Fix png endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wei committed Apr 11, 2024
1 parent 3760dcc commit 5fb7699
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions common/renderPNG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ import resvgWasm from '../public/resvg_bg.wasm?module'
import renderCardSVG from './renderSVG'
import QueryType from './types/queryType'

const initResvgWasm = resvg.initWasm(resvgWasm)
let resvgInitialized = false

const renderCardPNG = async (query: QueryType) => {
const [svg] = await Promise.all([renderCardSVG(query), initResvgWasm])
async function initResvg() {
if (!resvgInitialized) {
await resvg.initWasm(resvgWasm)
resvgInitialized = true
}
}

const [svg] = await Promise.all([renderCardSVG(query), initResvg()])

const resvgJS = new resvg.Resvg(svg, {
fitTo: {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const pngEndpoint = async (req: NextRequest) => {
}

export const config = {
runtime: 'edge'
runtime: 'nodejs'
}

export default pngEndpoint

0 comments on commit 5fb7699

Please sign in to comment.