From d1a81459265fbd66c0b82b884bc552036f945399 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Mon, 17 Oct 2022 16:45:39 -0400 Subject: [PATCH 1/2] feat: use ky instead of fetch for edge func --- package.json | 1 + pages/api/social-image.tsx | 21 +++++++++------------ yarn.lock | 5 +++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 7c206390e9..6b4063c5f5 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "fathom-client": "^3.4.1", "got": "^12.0.3", "isomorphic-unfetch": "^3.1.0", + "ky": "^0.31.4", "lqip-modern": "^1.2.0", "next": "^12.3.1", "notion-client": "^6.13.11", diff --git a/pages/api/social-image.tsx b/pages/api/social-image.tsx index 33662c4eea..11b9888dd4 100644 --- a/pages/api/social-image.tsx +++ b/pages/api/social-image.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import { NextRequest } from 'next/server' import { ImageResponse } from '@vercel/og' +import ky from 'ky' import { api, apiHost } from '@/lib/config' import { NotionPageInfo } from '@/lib/types' @@ -30,15 +31,11 @@ export default async function OGImage(req: NextRequest) { return new Response('Invalid notion page id', { status: 400 }) } - const pageInfoRes = await fetch(`${apiHost}${api.getNotionPageInfo}`, { - method: 'POST', - body: JSON.stringify({ pageId }), - headers: { 'Content-Type': 'application/json' } - }) - if (!pageInfoRes.ok) { - return new Response(pageInfoRes.statusText, { status: pageInfoRes.status }) - } - const pageInfo: NotionPageInfo = await pageInfoRes.json() + const pageInfo = await ky + .post(`${apiHost}${api.getNotionPageInfo}`, { + json: { pageId } + }) + .json() console.log(pageInfo) return new ImageResponse( @@ -86,7 +83,7 @@ export default async function OGImage(req: NextRequest) { style={{ position: 'relative', width: 900, - height: 450, + height: 465, display: 'flex', flexDirection: 'column', border: '16px solid rgba(0,0,0,0.3)', @@ -133,7 +130,7 @@ export default async function OGImage(req: NextRequest) {
Date: Mon, 17 Oct 2022 16:49:58 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8F=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6b4063c5f5..1b539fb015 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@keyvhq/core": "^1.6.9", "@keyvhq/redis": "^1.6.10", "@react-icons/all-files": "^4.1.0", - "@vercel/og": "^0.0.18", + "@vercel/og": "^0.0.19", "classnames": "^2.3.1", "date-fns": "^2.28.0", "expiry-map": "^2.0.0", diff --git a/yarn.lock b/yarn.lock index e3f3593cd2..289d91979a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -675,13 +675,13 @@ resolved "https://registry.npmjs.org/@use-it/event-listener/-/event-listener-0.1.7.tgz" integrity sha512-hgfExDzUU9uTRTPDCpw2s9jWTxcxmpJya3fK5ADpf5VDpSy8WYwY/kh28XE0tUcbsljeP8wfan48QvAQTSSa3Q== -"@vercel/og@^0.0.18": - version "0.0.18" - resolved "https://registry.yarnpkg.com/@vercel/og/-/og-0.0.18.tgz#4ee97eaf1f1fc2350447d3b43a1e4ee0c970de64" - integrity sha512-cEid22FkiNrgJ/HtawA6V3+x2jhP+KqwwNG97afFsFmZ/oPsh3Bm01NzCVSpeR96/aPaT2/59pbFXGxulxgp7g== +"@vercel/og@^0.0.19": + version "0.0.19" + resolved "https://registry.yarnpkg.com/@vercel/og/-/og-0.0.19.tgz#f0a796244c90b14aca40ee26225f2e046ccfda08" + integrity sha512-1LrPUlCoe8T+aEI1fGdvJDhwewK1/wpYlQnF+E9ERgJMFCnmWH4FA+NYBkQaJqxUUeHoutIxNZTHQFT39+I+BQ== dependencies: "@resvg/resvg-wasm" "2.0.0-alpha.4" - satori "0.0.40" + satori "0.0.42" yoga-wasm-web "0.1.2" "@xobotyi/scrollbar-width@^1.9.5": @@ -3283,10 +3283,10 @@ safe-regex-test@^1.0.0: get-intrinsic "^1.1.3" is-regex "^1.1.4" -satori@0.0.40: - version "0.0.40" - resolved "https://registry.yarnpkg.com/satori/-/satori-0.0.40.tgz#cc9c4b1c87820f4f62f90c9533d879cc74eb0194" - integrity sha512-SoXGq/89mBU34U1h4g/nXeL9DHS/Aof2iUL3FHabq+laSRQUSUI1ZhPhak3J6VMNW8wghYwJ/Bi7aF8FLPq9qQ== +satori@0.0.42: + version "0.0.42" + resolved "https://registry.yarnpkg.com/satori/-/satori-0.0.42.tgz#3cc4d7522e9264d1769a35f8da413811bb3b9752" + integrity sha512-ZZaNp2Ya1ACJ4Yf++e9Ccc1Rb6GcKjC9Nhcl4SQFcdM4VqCLfWHR6Iq7AdRCTcJDDuO8u/qGE2Cs+McVoqJenw== dependencies: "@shuding/opentype.js" "1.4.0-beta.0" css-background-parser "^0.1.0"