feat: 添加构建时间信息和相关功能
This commit is contained in:
2
back-end/dist/.env
vendored
2
back-end/dist/.env
vendored
@@ -12,7 +12,7 @@ APP_BASE_URL=https://bai-api.blv-oa.com
|
|||||||
|
|
||||||
# Database Configuration (Pocketbase)
|
# Database Configuration (Pocketbase)
|
||||||
POCKETBASE_API_URL=https://bai-api.blv-oa.com/pb/
|
POCKETBASE_API_URL=https://bai-api.blv-oa.com/pb/
|
||||||
POCKETBASE_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJfcGJfdXNlcnNfYXV0aF8iLCJleHAiOjE3NzQzNjEzMzIsImlkIjoiazQ0aHI5MW90bnBydG10IiwicmVmcmVzaGFibGUiOmZhbHNlLCJ0eXBlIjoiYXV0aCJ9.qm4E6xYrDbEpAfdxZnHHRZs_EqiwHgDIIwSBz2k90Nk
|
POCKETBASE_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJwYmNfMzE0MjYzNTgyMyIsImV4cCI6MTc3NDEwMTc4NiwiaWQiOiJmcnl2dG1qNnlwcHlmMXAiLCJyZWZyZXNoYWJsZSI6ZmFsc2UsInR5cGUiOiJhdXRoIn0.67DCKhqRQYF3ClPU_9mBgON_9ZDEy-NzqTeS50rGGZo
|
||||||
|
|
||||||
# WeChat Configuration
|
# WeChat Configuration
|
||||||
WECHAT_APPID=wx3bd7a7b19679da7a
|
WECHAT_APPID=wx3bd7a7b19679da7a
|
||||||
|
|||||||
3
back-end/dist/build-info.json
vendored
Normal file
3
back-end/dist/build-info.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"buildTime": "2026-03-20T14:36:26.964Z"
|
||||||
|
}
|
||||||
7
back-end/dist/spec/openapi.yaml
vendored
7
back-end/dist/spec/openapi.yaml
vendored
@@ -57,6 +57,11 @@ components:
|
|||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
example: success
|
example: success
|
||||||
|
build_time:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
description: 最近一次构建时间;开发模式下若未执行构建则可能为空
|
||||||
|
format: date-time
|
||||||
WechatProfileRequest:
|
WechatProfileRequest:
|
||||||
type: object
|
type: object
|
||||||
required: [users_name, users_phone_code, users_picture]
|
required: [users_name, users_phone_code, users_picture]
|
||||||
@@ -197,7 +202,7 @@ paths:
|
|||||||
post:
|
post:
|
||||||
tags: [系统]
|
tags: [系统]
|
||||||
summary: Test endpoint
|
summary: Test endpoint
|
||||||
description: Returns a hello world message
|
description: Returns a hello world message and build time
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Successful response
|
description: Successful response
|
||||||
|
|||||||
14
back-end/dist/src/routes/apiRoutes.js
vendored
14
back-end/dist/src/routes/apiRoutes.js
vendored
@@ -1,23 +1,29 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const { success } = require('../utils/response')
|
const { success } = require('../utils/response')
|
||||||
|
const { getBuildTimestamp } = require('../utils/buildInfo')
|
||||||
const wechatRoutes = require('./wechatRoutes')
|
const wechatRoutes = require('./wechatRoutes')
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.post('/test-helloworld', (req, res) => {
|
function respondHelloWorld(req, res) {
|
||||||
return success(res, '请求成功', {
|
return success(res, '请求成功', {
|
||||||
message: 'Hello, World!',
|
message: 'Hello, World!',
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
status: 'success',
|
status: 'success',
|
||||||
|
build_time: getBuildTimestamp(),
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
router.post('/health', (req, res) => {
|
function respondHealth(req, res) {
|
||||||
return success(res, '服务运行正常', {
|
return success(res, '服务运行正常', {
|
||||||
status: 'healthy',
|
status: 'healthy',
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
router.post('/test-helloworld', respondHelloWorld)
|
||||||
|
|
||||||
|
router.post('/health', respondHealth)
|
||||||
|
|
||||||
router.use('/wechat', wechatRoutes)
|
router.use('/wechat', wechatRoutes)
|
||||||
|
|
||||||
|
|||||||
30
back-end/dist/src/utils/buildInfo.js
vendored
Normal file
30
back-end/dist/src/utils/buildInfo.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
function getBuildInfoFilePath() {
|
||||||
|
return path.resolve(__dirname, '..', '..', 'build-info.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBuildTimestamp() {
|
||||||
|
if (process.env.BUILD_TIME) {
|
||||||
|
return process.env.BUILD_TIME
|
||||||
|
}
|
||||||
|
|
||||||
|
const filePath = getBuildInfoFilePath()
|
||||||
|
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(filePath, 'utf8')
|
||||||
|
const payload = JSON.parse(content)
|
||||||
|
return payload.buildTime || null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getBuildTimestamp,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user