Skip to content

Commit d1a8145

Browse files
feat: use ky instead of fetch for edge func
1 parent 98fdc0f commit d1a8145

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"fathom-client": "^3.4.1",
3737
"got": "^12.0.3",
3838
"isomorphic-unfetch": "^3.1.0",
39+
"ky": "^0.31.4",
3940
"lqip-modern": "^1.2.0",
4041
"next": "^12.3.1",
4142
"notion-client": "^6.13.11",

pages/api/social-image.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import { NextRequest } from 'next/server'
33

44
import { ImageResponse } from '@vercel/og'
5+
import ky from 'ky'
56

67
import { api, apiHost } from '@/lib/config'
78
import { NotionPageInfo } from '@/lib/types'
@@ -30,15 +31,11 @@ export default async function OGImage(req: NextRequest) {
3031
return new Response('Invalid notion page id', { status: 400 })
3132
}
3233

33-
const pageInfoRes = await fetch(`${apiHost}${api.getNotionPageInfo}`, {
34-
method: 'POST',
35-
body: JSON.stringify({ pageId }),
36-
headers: { 'Content-Type': 'application/json' }
37-
})
38-
if (!pageInfoRes.ok) {
39-
return new Response(pageInfoRes.statusText, { status: pageInfoRes.status })
40-
}
41-
const pageInfo: NotionPageInfo = await pageInfoRes.json()
34+
const pageInfo = await ky
35+
.post(`${apiHost}${api.getNotionPageInfo}`, {
36+
json: { pageId }
37+
})
38+
.json<NotionPageInfo>()
4239
console.log(pageInfo)
4340

4441
return new ImageResponse(
@@ -86,7 +83,7 @@ export default async function OGImage(req: NextRequest) {
8683
style={{
8784
position: 'relative',
8885
width: 900,
89-
height: 450,
86+
height: 465,
9087
display: 'flex',
9188
flexDirection: 'column',
9289
border: '16px solid rgba(0,0,0,0.3)',
@@ -133,7 +130,7 @@ export default async function OGImage(req: NextRequest) {
133130
<div
134131
style={{
135132
position: 'absolute',
136-
top: 32,
133+
top: 47,
137134
left: 104,
138135
height: 128,
139136
width: 128,
@@ -157,7 +154,7 @@ export default async function OGImage(req: NextRequest) {
157154
),
158155
{
159156
width: 1200,
160-
height: 600,
157+
height: 630,
161158
fonts: [
162159
{
163160
name: 'Inter',

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,11 @@ keyv@^4.0.0:
22332233
compress-brotli "^1.3.6"
22342234
json-buffer "3.0.1"
22352235

2236+
ky@^0.31.4:
2237+
version "0.31.4"
2238+
resolved "https://registry.yarnpkg.com/ky/-/ky-0.31.4.tgz#c629a707053a92611cefa23079a0b0b60131b4b4"
2239+
integrity sha512-OFuAD3riwhAfHK3J4FrhlujFRpm0ELBEfDHZfFpw89OTozQt3NLF39lNblUO5udj5vSkyaBKnLai/rFCzBfISQ==
2240+
22362241
levn@^0.4.1:
22372242
version "0.4.1"
22382243
resolved "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz"

0 commit comments

Comments
 (0)