tldraw/apps/dotcom-bookmark-extractor/api/bookmark.ts
Steve Ruiz d7002057d7
unbrivate, dot com in (#2475)
This PR moves the tldraw.com app into the public repo.

### Change Type

- [x] `internal` — Any other changes that don't affect the published
package[^2]

---------

Co-authored-by: Dan Groshev <git@dgroshev.com>
Co-authored-by: alex <alex@dytry.ch>
2024-01-16 14:38:05 +00:00

25 lines
562 B
TypeScript

// @ts-expect-error
import grabity from 'grabity'
import { runCorsMiddleware } from './_cors'
interface RequestBody {
url: string
}
interface ResponseBody {
title?: string
description?: string
image?: string
}
export default async function handler(req: any, res: any) {
try {
await runCorsMiddleware(req, res)
const { url } = typeof req.body === 'string' ? JSON.parse(req.body) : (req.body as RequestBody)
const it = await grabity.grabIt(url)
res.send(it)
} catch (error: any) {
console.error(error)
res.status(500).send(error.message)
}
}