wing-ops/frontend/src/App.tsx
htlee 5e4044d461 fix: 하드코딩 URL 제거 + 환경변수 전환
- App.tsx: 중복 API_BASE_URL 정의 → @common/services/api import
- MapView.tsx: GeoServer localhost:8080 → VITE_GEOSERVER_URL 환경변수
- ShipInsurance.tsx: 해운조합 API URL → VITE_HAEWOON_API_URL 환경변수
- server.ts CORS: 운영 도메인 → FRONTEND_URL 환경변수 통합
- server.ts CSP: localhost 허용을 개발 환경(NODE_ENV≠production)에만 적용

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 01:36:07 +09:00

124 lines
3.6 KiB
TypeScript
Executable File

import { useState, useEffect } from 'react'
import { GoogleOAuthProvider } from '@react-oauth/google'
import type { MainTab } from '@common/types/navigation'
import { MainLayout } from '@common/components/layout/MainLayout'
import { LoginPage } from '@common/components/auth/LoginPage'
import { registerMainTabSwitcher } from '@common/hooks/useSubMenu'
import { useAuthStore } from '@common/store/authStore'
import { useMenuStore } from '@common/store/menuStore'
import { API_BASE_URL } from '@common/services/api'
import { OilSpillView } from '@tabs/prediction'
import { ReportsView } from '@tabs/reports'
import { HNSView } from '@tabs/hns'
import { AerialView } from '@tabs/aerial'
import { AssetsView } from '@tabs/assets'
import { BoardView } from '@tabs/board'
import { WeatherView } from '@tabs/weather'
import { IncidentsView } from '@tabs/incidents'
import { AdminView } from '@tabs/admin'
import { PreScatView } from '@tabs/scat'
import { RescueView } from '@tabs/rescue'
const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID || ''
function App() {
const [activeMainTab, setActiveMainTab] = useState<MainTab>('prediction')
const { isAuthenticated, isLoading, checkSession } = useAuthStore()
const { loadMenuConfig } = useMenuStore()
useEffect(() => {
checkSession()
}, [checkSession])
useEffect(() => {
if (isAuthenticated) {
loadMenuConfig()
}
}, [isAuthenticated, loadMenuConfig])
useEffect(() => {
registerMainTabSwitcher(setActiveMainTab)
}, [])
// 감사 로그: 탭 이동 기록
useEffect(() => {
if (!isAuthenticated) return
const blob = new Blob(
[JSON.stringify({ action: 'TAB_VIEW', detail: activeMainTab })],
{ type: 'text/plain' }
)
navigator.sendBeacon(`${API_BASE_URL}/audit/log`, blob)
}, [activeMainTab, isAuthenticated])
// 세션 확인 중 스플래시
if (isLoading) {
return (
<div style={{
width: '100vw', height: '100vh', display: 'flex',
flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
background: '#001028', gap: 16,
}}>
<img src="/wing_logo_text_white.svg" alt="WING" style={{ height: 28, opacity: 0.8 }} />
<div style={{
width: 32, height: 32, border: '3px solid rgba(6,182,212,0.2)',
borderTop: '3px solid rgba(6,182,212,0.8)', borderRadius: '50%',
animation: 'loginSpin 0.8s linear infinite',
}} />
</div>
)
}
// 미인증 → 로그인 페이지
if (!isAuthenticated) {
return <LoginPage />
}
const renderView = () => {
switch (activeMainTab) {
case 'prediction':
return <OilSpillView />
case 'reports':
return <ReportsView />
case 'hns':
return <HNSView />
case 'aerial':
return <AerialView />
case 'assets':
return <AssetsView />
case 'board':
return <BoardView />
case 'weather':
return <WeatherView />
case 'incidents':
return <IncidentsView />
case 'scat':
return <PreScatView />
case 'admin':
return <AdminView />
case 'rescue':
return <RescueView />
default:
return <div className="flex items-center justify-center h-full text-text-3"> ...</div>
}
}
return (
<MainLayout activeMainTab={activeMainTab} onMainTabChange={setActiveMainTab}>
{renderView()}
</MainLayout>
)
}
function AppWithProviders() {
if (!GOOGLE_CLIENT_ID) {
return <App />
}
return (
<GoogleOAuthProvider clientId={GOOGLE_CLIENT_ID}>
<App />
</GoogleOAuthProvider>
)
}
export default AppWithProviders