From ac7f4011cd4dfa0938aea888e7f004d93321c9af Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 7 Jan 2024 23:22:39 +0800 Subject: [PATCH] feat: add version display --- src/client/pages/Layout.tsx | 9 +++++++++ src/server/main.ts | 2 ++ src/server/router/health.ts | 10 ++++++++++ src/shared/config.ts | 3 +++ src/shared/index.ts | 1 + 5 files changed, 25 insertions(+) create mode 100644 src/server/router/health.ts create mode 100644 src/shared/config.ts diff --git a/src/client/pages/Layout.tsx b/src/client/pages/Layout.tsx index f82a191..63aebcf 100644 --- a/src/client/pages/Layout.tsx +++ b/src/client/pages/Layout.tsx @@ -6,6 +6,7 @@ import { Button, Dropdown } from 'antd'; import { useUserStore } from '../store/user'; import { useLogout } from '../api/model/user'; import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher'; +import { version } from '../../shared'; export const Layout: React.FC = React.memo(() => { const [params] = useSearchParams(); @@ -66,6 +67,14 @@ export const Layout: React.FC = React.memo(() => { logout(); }, }, + { + type: 'divider', + }, + { + key: 'version', + label: `v${version}`, + disabled: true, + }, ], }} > diff --git a/src/server/main.ts b/src/server/main.ts index 3ba3b8b..31775b4 100644 --- a/src/server/main.ts +++ b/src/server/main.ts @@ -26,6 +26,7 @@ import { serverStatusRouter } from './router/serverStatus'; import { initCronjob } from './cronjob'; import { logger } from './utils/logger'; import { monitorRouter } from './router/monitor'; +import { healthRouter } from './router/health'; const port = settings.port; @@ -56,6 +57,7 @@ app.use( }) ); +app.use('/health', healthRouter); app.use('/api/website', websiteRouter); app.use('/api/workspace', workspaceRouter); app.use('/monitor', monitorRouter); diff --git a/src/server/router/health.ts b/src/server/router/health.ts new file mode 100644 index 0000000..efb6059 --- /dev/null +++ b/src/server/router/health.ts @@ -0,0 +1,10 @@ +import { Router } from 'express'; +import { version } from '../../shared'; + +export const healthRouter = Router(); + +healthRouter.get('/', async (req, res) => { + res.json({ + version, + }); +}); diff --git a/src/shared/config.ts b/src/shared/config.ts new file mode 100644 index 0000000..a4190bb --- /dev/null +++ b/src/shared/config.ts @@ -0,0 +1,3 @@ +import packageJson from '../../package.json'; + +export const version = packageJson.version; diff --git a/src/shared/index.ts b/src/shared/index.ts index cd36ae7..74d231d 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,3 +1,4 @@ +export * from './config'; export * from './date'; export * from './server'; export * from './regex';