|
1 | 1 | export const config = { |
2 | | - matcher: ['/meme/quiz', '/meme/:memeId'], |
| 2 | + matcher: ['/meme/:memeId'], |
3 | 3 | }; |
4 | 4 |
|
5 | 5 | export default async function middleware(request: Request) { |
6 | 6 | const url = new URL(request.url); |
7 | | - const pathSegments = url.pathname.split('/'); |
8 | | - const path = pathSegments[2]; |
9 | | - |
10 | | - // 기본 HTML을 가져옵니다 |
11 | | - const res = await fetch(new URL('/', request.url)); |
12 | | - const html = await res.text(); |
13 | | - |
14 | | - // /meme/quiz 경로인 경우 퀴즈 페이지용 OG 태그 설정 |
15 | | - if (path === 'quiz') { |
16 | | - const modifiedHtml = html |
17 | | - .replace( |
18 | | - /<meta\s+property="og:title"\s+content="[^"]*"[^>]*>/, |
19 | | - `<meta property="og:title" content="Meme Wiki - 밈 퀴즈" />`, |
20 | | - ) |
21 | | - .replace( |
22 | | - /<meta\s+property="og:description"\s+content="[^"]*"[^>]*>/, |
23 | | - `<meta property="og:description" content="재미있는 밈 퀴즈를 풀어보세요!" />`, |
24 | | - ) |
25 | | - .replace( |
26 | | - /<meta\s+property="og:image"\s+content="[^"]*"[^>]*>/, |
27 | | - `<meta property="og:image" content="${url.origin}/thumbnail.png" />`, |
28 | | - ) |
29 | | - .replace( |
30 | | - /<meta\s+property="og:url"\s+content="[^"]*"[^>]*>/, |
31 | | - `<meta property="og:url" content="${url.href}" />`, |
32 | | - ) |
33 | | - .replace( |
34 | | - /<meta\s+property="twitter:title"\s+content="[^"]*"[^>]*>/, |
35 | | - `<meta property="twitter:title" content="Meme Wiki - 밈 퀴즈" />`, |
36 | | - ) |
37 | | - .replace( |
38 | | - /<meta\s+property="twitter:description"\s+content="[^"]*"[^>]*>/, |
39 | | - `<meta property="twitter:description" content="재미있는 밈 퀴즈를 풀어보세요!" />`, |
40 | | - ) |
41 | | - .replace( |
42 | | - /<meta\s+property="twitter:image"\s+content="[^"]*"[^>]*>/, |
43 | | - `<meta property="twitter:image" content="${url.origin}/thumbnail.png" />`, |
44 | | - ); |
45 | | - |
46 | | - return new Response(modifiedHtml, { |
47 | | - status: 200, |
48 | | - headers: { |
49 | | - 'content-type': 'text/html;charset=UTF-8', |
50 | | - 'cache-control': 'no-cache, no-store, must-revalidate', |
51 | | - pragma: 'no-cache', |
52 | | - expires: '0', |
53 | | - }, |
54 | | - }); |
55 | | - } |
| 7 | + const memeId = url.pathname.split('/').pop(); |
56 | 8 |
|
57 | 9 | // /meme/{id} 경로에 대한 처리 |
58 | 10 | try { |
59 | 11 | const response = await fetch( |
60 | | - `https://api.meme-wiki.net/api/memes/${path}`, |
| 12 | + `https://api.meme-wiki.net/api/memes/${memeId}`, |
61 | 13 | { |
62 | 14 | headers: { |
63 | 15 | Accept: 'application/json', |
@@ -96,7 +48,7 @@ export default async function middleware(request: Request) { |
96 | 48 | ) |
97 | 49 | .replace( |
98 | 50 | /<meta\s+property="og:url"\s+content="[^"]*"[^>]*>/, |
99 | | - `<meta property="og:url" content="https://meme-wiki.net/meme/${path}" />`, |
| 51 | + `<meta property="og:url" content="${url.origin}/meme/${memeId}" />`, |
100 | 52 | ) |
101 | 53 | .replace( |
102 | 54 | /<meta\s+property="twitter:title"\s+content="[^"]*"[^>]*>/, |
|
0 commit comments