feat: 지역 검색 페이지에 오늘 날씨·각을 서버가 채워 준다 (nginx → /v1/seo/today, 실패하면 정적 HTML)

This commit is contained in:
minaChoi committed 2026-10-14 09:32:23 +09:00
1 parent 2ca060b626
commit a68268234d
8 files changed
+183 -1

No files matched your search

+17
View File
@@ -31,6 +31,23 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
# 지역 검색 페이지: 백엔드가 정적 HTML(today/…/….html)에 오늘 날씨를 채워 준다. 백엔드가 안 되면 정적 HTML 그대로
location ~ ^/today/[a-z]+/[a-z]+$ {
resolver 127.0.0.11 valid=10s ipv6=off;
set $api http://backend:9800;
proxy_pass $api/v1/seo$uri;
proxy_set_header Host $host;
proxy_connect_timeout 3s;
proxy_read_timeout 20s;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @static;
}
location @static {
add_header Cache-Control "no-cache";
try_files $uri.html /index.html;
}
# SPA: /gak 처럼 빌드 때 만든 페이지별 HTML(gak.html)이 있으면 그것을, 없으면 index.html. 폴더는 안 찾는다 (/season 이 이미지 폴더 public/season 과 겹쳐 403)
location / {
add_header Cache-Control "no-cache";
+4 -1
View File
@@ -12,7 +12,7 @@ const gakList = `<ul>${gaks.map((g) => `<li><b>${g.name}</b>: ${g.description}</
const regionPages: RegionPage[] = JSON.parse(readFileSync(resolve(import.meta.dirname, 'seo/region.json'), 'utf8'))
/** 검색 로봇이 처음 받는 페이지별 HTML. 바뀌지 않는 소개 글만 넣고, 날씨 값은 앱이 뜬 뒤 불러온다 */
const PAGES: { path: string; title: string; description: string; body: string }[] = [
const PAGES: { path: string; title: string; description: string; body: string; code?: string }[] = [
{
path: 'gak',
title: '오늘의 각 · 세차각·빨래각·러닝각 점수 | 날씨각',
@@ -46,6 +46,7 @@ for (const r of regionPages) {
const parts = r.regions.length > 1 ? `<p>${r.name}는 ${r.regions.map((g) => g.name.split(' ').at(-1)).join(', ')}별로 따로 계산해요.</p>` : ''
PAGES.push({
path: `today/${r.path}`,
code: r.main,
title: `오늘 ${r.name} 날씨, 뭐 할까? | 날씨각`,
description: `오늘 ${r.name} 날씨로 세차·빨래·러닝·피크닉 하기 좋은지 아침·낮·저녁·밤 점수로 알려 드려요. 노을 시각과 미세먼지도 함께 확인하세요.`,
body: `<h1>오늘 ${r.name} 날씨, 뭐 할까?</h1><p>${r.name}의 기상청 예보와 미세먼지로 오늘 하기 좋은 일을 점수로 알려 드려요. 아침, 낮, 저녁, 밤마다 따로 계산해요.</p>${parts}<p>세차각, 빨래각, 러닝각, 우산각처럼 하고 싶은 일이 오늘 날씨에 맞는지 매일 새로 계산하고, 노을이 가장 붉은 시각과 가까운 노을 명소도 알려 드려요.</p>${near.length ? `<h2>${r.name.split(' ')[0]} 다른 지역 날씨</h2><ul>${near.map((o) => `<li><a href="/today/${o.path}">${o.name}</a></li>`).join('')}</ul>` : ''}`,
@@ -74,6 +75,8 @@ function seoPages(): Plugin {
.replace(/(<meta property="og:url" content=")[^"]*"/, `$1${url}"`)
.replace(/(<link rel="canonical" href=")[^"]*"/, `$1${url}"`)
.replace(/<main>[\s\S]*<\/main>/, `<main>${p.body}<p><a href="/">날씨각 처음으로</a></p></main>`)
// 서버가 오늘 날씨를 채울 때 이 페이지의 구를 알아보는 표시
.replace('</head>', p.code ? `<meta name="region-code" content="${p.code}" />\n </head>` : '</head>')
const file = resolve(outDir, `${p.path}.html`)
mkdirSync(dirname(file), { recursive: true })
writeFileSync(file, html)