- visit-beacon: hydrate 직후와 탭 이동(hashchange) 때 sendBeacon('/v1/track/view'). 발행 경로(/s/…)가
아니면 보내지 않는다 — 같은 번들이 /preview 에서도 돈다. localStorage 'web4ai.stats.disabled' 로 운영자
본인 방문을 뺀다(접근이 막히면 그냥 센다). 전송 실패는 손님 화면에 올리지 않는다
- entry-client: 발행 페이지(hydrate 분기)에서만 호출 — 미리보기·개발 픽스처 분기는 보내지 않는다
- vite.config: 5173 에서 발행 페이지의 상대 경로 /v1/… 가 백엔드에 닿지 않아 날씨·후기·비콘이 개발 서버에서만
죽었다 → /v1 프록시(DEV_API_PROXY, compose 가 solution-backend:9800 으로 준다). 빌더 미리보기 iframe
(/preview?placeId=…)도 빌더 라우터로 떨어져 미리보기 칸에 빌더 자신의 404 가 떴다 → /preview 를 :3001 로.
둘 다 개발 서버 전용이라 운영 번들에는 들어가지 않는다
- SERVERS.md: 기존 발행 사이트는 다시 발행해야 집계가 시작된다(9/15 이후 기동은 공용 자산만 깔고 옛 HTML 의
번들 주소는 바꾸지 않는다). republish_all.py 는 굽지 않고 Azure 로 다시 올릴 뿐이라 비콘이 안 들어간다
site vitest visit-beacon 6 passed, site lint 통과. 5173 실측: 사람 1건 저장, 10초 안 반복·봇·미리보기·
2KB 초과 본문은 저장 안 됨, #/stay 는 별도 경로, /preview 는 미리보기 셸. site 전체 132 passed · 1 failed
(publish-version.test.ts 자식 프로세스 0xC0000409 — 이 변경을 뺀 상태에서도 같은 Windows 환경 실패).
100 lines
3.0 KiB
TypeScript
100 lines
3.0 KiB
TypeScript
import {StrictMode, useEffect} from 'react';
|
|
import {createRoot, hydrateRoot} from 'react-dom/client';
|
|
import {templateOf, type SitePayload} from '@o2o/shared';
|
|
import {App} from './App';
|
|
import {sendVisit} from './lib/visit-beacon';
|
|
import {fontHref, themeVars} from '@site/seo/head';
|
|
import './index.css';
|
|
|
|
declare global {
|
|
interface Window {
|
|
__SITE_PAYLOAD__?: SitePayload;
|
|
}
|
|
}
|
|
|
|
const container = document.getElementById('root')!;
|
|
const injected = window.__SITE_PAYLOAD__;
|
|
|
|
function signalPreviewPainted(ok: boolean) {
|
|
if (window.parent === window) return;
|
|
const post = () => window.parent.postMessage({type: 'o2o:preview-painted', ok}, window.location.origin);
|
|
requestAnimationFrame(() => requestAnimationFrame(post));
|
|
}
|
|
|
|
function PreviewReady() {
|
|
useEffect(() => signalPreviewPainted(true), []);
|
|
return null;
|
|
}
|
|
|
|
async function renderPreview(placeId: string) {
|
|
const token = (() => {
|
|
try {
|
|
return localStorage.getItem('o2o-web4ai.accessToken');
|
|
} catch {
|
|
return null;
|
|
}
|
|
})();
|
|
|
|
const res = await fetch(`/v1/place/${placeId}/site/preview`, {
|
|
headers: token ? {Authorization: `Bearer ${token}`} : {},
|
|
});
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
const payload = (await res.json()) as SitePayload;
|
|
templateOf(payload.theme.templateId);
|
|
|
|
for (const [name, value] of Object.entries(themeVars(payload))) {
|
|
document.documentElement.style.setProperty(name, value);
|
|
}
|
|
|
|
const font = document.createElement('link');
|
|
font.rel = 'stylesheet';
|
|
font.href = fontHref(payload);
|
|
document.head.appendChild(font);
|
|
await new Promise<void>((resolve) => {
|
|
font.addEventListener('load', () => resolve(), {once: true});
|
|
font.addEventListener('error', () => resolve(), {once: true});
|
|
setTimeout(resolve, 2500);
|
|
});
|
|
try {
|
|
await document.fonts.ready;
|
|
} catch {
|
|
/* 폰트 API 가 없거나 실패해도 그린다 */
|
|
}
|
|
|
|
createRoot(container).render(
|
|
<StrictMode>
|
|
<App payload={payload} />
|
|
<PreviewReady />
|
|
</StrictMode>,
|
|
);
|
|
signalPreviewPainted(true);
|
|
}
|
|
|
|
const previewPlaceId = new URLSearchParams(window.location.search).get('placeId');
|
|
|
|
if (injected) {
|
|
// 서버가 그린 마크업과 1:1이어야 하므로 payload를 바꾸지 않는다.
|
|
hydrateRoot(
|
|
container,
|
|
<StrictMode>
|
|
<App payload={injected} />
|
|
</StrictMode>,
|
|
);
|
|
// 발행 페이지에서만 센다 — 미리보기(renderPreview)·개발 픽스처 분기는 보내지 않는다.
|
|
sendVisit();
|
|
} else if (previewPlaceId) {
|
|
void renderPreview(previewPlaceId).catch((ex: unknown) => {
|
|
container.textContent = `미리보기를 불러오지 못했습니다 — ${ex instanceof Error ? ex.message : String(ex)}`;
|
|
signalPreviewPainted(false);
|
|
});
|
|
} else {
|
|
// 개발 서버 전용 데모 payload.
|
|
void import('./fixtures/moonlight-stay').then(({MOONLIGHT_STAY_PAYLOAD}) => {
|
|
createRoot(container).render(
|
|
<StrictMode>
|
|
<App payload={MOONLIGHT_STAY_PAYLOAD} />
|
|
</StrictMode>,
|
|
);
|
|
});
|
|
}
|