Skip to content

Commit 8326faa

Browse files
committed
fix(seo): Vercel OG 폰트 경로 보정
Vercel Node.js 함수에서 번들된 URL 객체를 readFile 경로로 인식하지 못해 OG endpoint가 500을 반환했습니다. process.cwd() 기준 문자열 경로로 폰트 위치를 계산해 배포 환경에서도 같은 파일을 읽도록 변경했습니다.
1 parent e4e9ffa commit 8326faa

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

app/api/og/route.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { readFile } from 'node:fs/promises';
2+
import { join } from 'node:path';
23
import { ImageResponse } from 'next/og';
34
import type { NextRequest } from 'next/server';
45
import { SITE_NAME } from '@/site/config/site';
56

67
export const runtime = 'nodejs';
78

8-
const fontUrl = new URL('./Pretendard-Bold.ttf', import.meta.url);
9+
const fontPath = join(process.cwd(), 'app', 'api', 'og', 'Pretendard-Bold.ttf');
910
let fontDataPromise: Promise<ArrayBuffer> | null = null;
1011

1112
function loadFontData(): Promise<ArrayBuffer> {
1213
if (!fontDataPromise) {
13-
fontDataPromise = readFile(fontUrl).then(
14+
fontDataPromise = readFile(fontPath).then(
1415
(font) =>
1516
font.buffer.slice(
1617
font.byteOffset,

docs/adr/0025-use-node-runtime-for-og-image-route.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ production build는 성공했지만 출력물을 배포하는 단계에서 실
1818

1919
- `/api/og` Route Handler는 `nodejs` runtime을 명시한다.
2020
- 번들된 Pretendard 폰트는 `node:fs/promises``readFile`로 지연 로드한다.
21+
- 폰트 위치는 `process.cwd()`에서 시작하는 문자열 경로로 계산해 Vercel Node.js
22+
함수에서도 같은 파일을 찾도록 한다.
2123
- 폰트 데이터 Promise를 module scope에 캐시해 같은 인스턴스에서 반복해서
2224
파일을 읽지 않는다.
2325
- route 테스트는 실제 번들 폰트로 PNG를 생성하고 Node.js runtime 설정을 함께

0 commit comments

Comments
 (0)