import { VercelRequest , VercelResponse , } from '@vercel/node' ; import { renderToString } from 'react-dom/server' ; import { CurrentGames } from '../src/components/chess/CurrentGames' ; import { currentGames , convertFen , getPieces , } from '../src/services/chesscom' ; param { VercelRequest } req param { VercelResponse } res export default async function ( req , res ) { const { games = [ ] , } = await currentGames ( ) ; let pieceImages = await getPieces ( ) ; games . length = Math . min ( games . length , 3 ) ; const convertedGames = await Promise . all ( games . map ( async ( game ) => { const isWhite = game . white . includes ( 'andyruwruw' ) ; const white = ( game . white . split ( '/' ) . reverse ( ) ) [ 0 ] ; const black = ( game . black . split ( '/' ) . reverse ( ) ) [ 0 ] ; return { black , isWhite , noGame : false , position : await convertFen ( isWhite , game . fen ) , white , } ; } ) ) ; for ( let i = convertedGames . length ; i < 3 ; i ++ ) { convertedGames . push ( { black : null , isWhite : true , noGame : true , position : convertFen ( true , '8/8/8/8/8/8/8/8/' ) , white : null , } ) ; } res . setHeader ( 'Content-Type' , 'image/svg+xml' ) ; res . setHeader ( 'Cache-Control' , 's-maxage=1, stale-while-revalidate' ) ; const text = renderToString ( CurrentGames ( { games : convertedGames , pieceImages , } ) ) ; return res . send ( text ) ; }