feat: add health check page (#244)
This commit is contained in:
18
frontend/components/Footer.tsx
Normal file
18
frontend/components/Footer.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Link, NextUiLinkClasses } from '@/src/i18n/routing';
|
||||
import { LocaleCodeType } from '@/types/locale';
|
||||
|
||||
type Props = {
|
||||
locale: LocaleCodeType;
|
||||
};
|
||||
|
||||
export default function Footer({ locale }: Props) {
|
||||
return (
|
||||
<div className="w-full text-center py-2 px-6 flex flex-wrap justify-center items-center gap-4">
|
||||
<div>Copyright © 2024-present UnitTCMS</div>
|
||||
|
||||
<Link href={'/health'} locale={locale} className={`${NextUiLinkClasses} text-gray-500 hover:text-gray-700`}>
|
||||
Status
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -114,6 +114,14 @@
|
||||
"not_own_any_projects": "You don't own any projects.",
|
||||
"find_projects": "Find projects"
|
||||
},
|
||||
"Health": {
|
||||
"health_check": "Health Check",
|
||||
"status": "Status",
|
||||
"ok": "OK",
|
||||
"error": "Error",
|
||||
"api_server": "API Server",
|
||||
"unittcms_version": "UnitTCMS Version"
|
||||
},
|
||||
"Admin": {
|
||||
"user_management": "User Management",
|
||||
"avatar": "Avatar",
|
||||
|
||||
@@ -133,6 +133,14 @@
|
||||
"lost_admin_auth": "管理者権限を失いました",
|
||||
"at_least": "最低1人以上の管理者が必要です。"
|
||||
},
|
||||
"Health": {
|
||||
"health_check": "ヘルスチェック",
|
||||
"status": "ステータス",
|
||||
"ok": "正常",
|
||||
"error": "エラー",
|
||||
"api_server": "APIサーバー",
|
||||
"unittcms_version": "UnitTCMS バージョン"
|
||||
},
|
||||
"Projects": {
|
||||
"project_list": "プロジェクト一覧",
|
||||
"new_project": "新規プロジェクト",
|
||||
|
||||
@@ -97,13 +97,6 @@ export default function HeaderNavbarMenu({ messages, locale }: Props) {
|
||||
<p className="font-bold text-inherit ms-1">UnitTCMS</p>
|
||||
</Link>
|
||||
</NavbarBrand>
|
||||
<NavbarItem className="hidden md:block">
|
||||
<Chip size="sm" variant="flat">
|
||||
<Link className="data-[active=true]:text-primary data-[active=true]:font-medium" href="/" locale={locale}>
|
||||
1.0.0-beta.14
|
||||
</Link>
|
||||
</Chip>
|
||||
</NavbarItem>
|
||||
{commonLinks.map((link) =>
|
||||
link.isExternal ? (
|
||||
<NavbarItem key={link.uid} className="hidden md:block">
|
||||
|
||||
@@ -6,6 +6,7 @@ import DemoImage from './DemoImage';
|
||||
import { title, subtitle } from '@/components/primitives';
|
||||
import { PageType } from '@/types/base';
|
||||
import { LocaleCodeType } from '@/types/locale';
|
||||
import Footer from '@/components/Footer';
|
||||
|
||||
export default function LandingPage({ params }: PageType) {
|
||||
const t = useTranslations('Index');
|
||||
@@ -98,9 +99,7 @@ export default function LandingPage({ params }: PageType) {
|
||||
</div>
|
||||
|
||||
<Divider className="my-12" />
|
||||
<div className="w-full text-center py-2">
|
||||
<div>Copyright © 2024-present UnitTCMS</div>
|
||||
</div>
|
||||
<Footer locale={params.locale as LocaleCodeType} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Button, Link as NextUiLink } from '@heroui/react';
|
||||
import { MoveUpRight } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { title, subtitle } from '@/components/primitives';
|
||||
import { LocaleCodeType } from '@/types/locale';
|
||||
|
||||
85
frontend/src/app/[locale]/health/HealthPage.tsx
Normal file
85
frontend/src/app/[locale]/health/HealthPage.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
'use client';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Table, TableBody, TableRow, TableHeader, TableCell, Chip, TableColumn } from '@heroui/react';
|
||||
import { LocaleCodeType } from '@/types/locale';
|
||||
import { HealthMessages } from '@/types/health';
|
||||
import Config from '@/config/config';
|
||||
const apiServer = Config.apiServer;
|
||||
|
||||
type Props = {
|
||||
messages: HealthMessages;
|
||||
locale: LocaleCodeType;
|
||||
};
|
||||
|
||||
async function fetchHealth() {
|
||||
const url = `${apiServer}/health`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
console.log('Error fetching health data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function HealthPage({ messages, locale }: Props) {
|
||||
const [isFetching, setIsFetching] = useState<boolean>(true);
|
||||
const [status, setStatus] = useState<string>('loading...');
|
||||
const apiOrigin = Config.apiServer;
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchDataEffect() {
|
||||
try {
|
||||
setIsFetching(true);
|
||||
const data = await fetchHealth();
|
||||
setStatus(data.status);
|
||||
setIsFetching(false);
|
||||
} catch (error: any) {
|
||||
console.error('Error in effect:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
fetchDataEffect();
|
||||
}, [locale]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="container mx-auto max-w-3xl pt-16 px-6 flex-grow">
|
||||
<div className="w-full p-3 flex items-center justify-between">
|
||||
<h3 className="font-bold">{messages.health_check}</h3>
|
||||
</div>
|
||||
|
||||
<Table hideHeader aria-label="API server status">
|
||||
<TableHeader>
|
||||
<TableColumn>dummy</TableColumn>
|
||||
<TableColumn>dummy</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow key="1">
|
||||
<TableCell>{messages.unittcms_version}</TableCell>
|
||||
<TableCell>1.0.0-beta.14</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="2">
|
||||
<TableCell>{messages.api_server}</TableCell>
|
||||
<TableCell>{apiOrigin}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="3">
|
||||
<TableCell>{messages.status}</TableCell>
|
||||
<TableCell>
|
||||
{isFetching ? (
|
||||
<Chip>Loading...</Chip>
|
||||
) : (
|
||||
<Chip color={status === 'ok' ? 'success' : 'danger'}>{status}</Chip>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
32
frontend/src/app/[locale]/health/page.tsx
Normal file
32
frontend/src/app/[locale]/health/page.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import HealthPage from './HealthPage';
|
||||
import { PageType } from '@/types/base';
|
||||
import { LocaleCodeType } from '@/types/locale';
|
||||
import { HealthMessages } from '@/types/health';
|
||||
|
||||
export async function generateMetadata({ params: { locale } }: { params: { locale: LocaleCodeType } }) {
|
||||
const t = await getTranslations({ locale, namespace: 'Health' });
|
||||
return {
|
||||
title: `${t('health_check')} | UnitTCMS`,
|
||||
robots: { index: false, follow: false },
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page({ params }: PageType) {
|
||||
const t = useTranslations('Health');
|
||||
const messages: HealthMessages = {
|
||||
health_check: t('health_check'),
|
||||
status: t('status'),
|
||||
ok: t('ok'),
|
||||
error: t('error'),
|
||||
api_server: t('api_server'),
|
||||
unittcms_version: t('unittcms_version'),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full flex items-center justify-center">
|
||||
<HealthPage messages={messages} locale={params.locale as LocaleCodeType} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
8
frontend/types/health.ts
Normal file
8
frontend/types/health.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export type HealthMessages = {
|
||||
health_check: string;
|
||||
status: string;
|
||||
ok: string;
|
||||
error: string;
|
||||
api_server: string;
|
||||
unittcms_version: string;
|
||||
};
|
||||
Reference in New Issue
Block a user