fix: 移除繁体转简体和资讯
This commit is contained in:
Binary file not shown.
@@ -7,12 +7,19 @@ const { WebSocketServer } = require('ws')
|
||||
const routes = require('./routes')
|
||||
const { getSituation } = require('./situationData')
|
||||
|
||||
const swaggerUi = require('swagger-ui-express')
|
||||
const openApiSpec = require('./openapi')
|
||||
|
||||
const app = express()
|
||||
const PORT = process.env.API_PORT || 3001
|
||||
|
||||
app.set('trust proxy', 1)
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
|
||||
// Swagger 文档
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(openApiSpec))
|
||||
|
||||
app.use('/api', routes)
|
||||
app.get('/api/health', (_, res) => res.json({ ok: true }))
|
||||
app.post('/api/crawler/notify', (_, res) => {
|
||||
@@ -58,4 +65,5 @@ function notifyCrawlerUpdate() {
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`API + WebSocket running at http://localhost:${PORT}`)
|
||||
console.log(`Swagger docs at http://localhost:${PORT}/api-docs`)
|
||||
})
|
||||
|
||||
134
server/openapi.js
Normal file
134
server/openapi.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* OpenAPI 3.0 规范,供 Swagger UI 展示
|
||||
*/
|
||||
const PORT = process.env.API_PORT || 3001
|
||||
|
||||
module.exports = {
|
||||
openapi: '3.0.3',
|
||||
info: {
|
||||
title: 'US-Iran Military Dashboard API',
|
||||
version: '1.0.0',
|
||||
description: '美伊军事态势面板后端接口',
|
||||
},
|
||||
servers: [{ url: `http://localhost:${PORT}`, description: '本地' }],
|
||||
paths: {
|
||||
'/api/situation': {
|
||||
get: {
|
||||
summary: '获取态势数据',
|
||||
description: '战损、基地、新闻、冲突事件等完整态势',
|
||||
tags: ['态势'],
|
||||
responses: {
|
||||
200: {
|
||||
description: '态势 JSON',
|
||||
content: { 'application/json': { schema: { type: 'object' } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'/api/db/dashboard': {
|
||||
get: {
|
||||
summary: '数据库面板',
|
||||
description: '各表原始数据,供 /db 调试页',
|
||||
tags: ['调试'],
|
||||
responses: {
|
||||
200: {
|
||||
description: '各表数据',
|
||||
content: { 'application/json': { schema: { type: 'object' } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'/api/visit': {
|
||||
post: {
|
||||
summary: '来访统计',
|
||||
description: '记录 IP,返回当前在看人数和累积访问',
|
||||
tags: ['统计'],
|
||||
responses: {
|
||||
200: {
|
||||
description: 'OK',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
viewers: { type: 'number' },
|
||||
cumulative: { type: 'number' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'/api/feedback': {
|
||||
post: {
|
||||
summary: '提交反馈',
|
||||
description: '留言 1–2000 字',
|
||||
tags: ['反馈'],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
required: ['content'],
|
||||
properties: { content: { type: 'string', maxLength: 2000 } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: { description: 'ok: true' },
|
||||
400: { description: '内容超长或为空' },
|
||||
},
|
||||
},
|
||||
},
|
||||
'/api/health': {
|
||||
get: {
|
||||
summary: '健康检查',
|
||||
tags: ['系统'],
|
||||
responses: { 200: { description: 'ok: true' } },
|
||||
},
|
||||
},
|
||||
'/api/crawler/notify': {
|
||||
post: {
|
||||
summary: '爬虫通知',
|
||||
description: '爬虫更新后调用,触发前端推送',
|
||||
tags: ['系统'],
|
||||
responses: { 200: { description: 'ok' } },
|
||||
},
|
||||
},
|
||||
'/api/stats': {
|
||||
get: {
|
||||
summary: '统计快照',
|
||||
description: 'viewers / cumulative,不写入',
|
||||
tags: ['统计'],
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
viewers: { type: 'number' },
|
||||
cumulative: { type: 'number' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'/api/events': {
|
||||
get: {
|
||||
summary: '冲突事件',
|
||||
description: '冲突事件列表及统计',
|
||||
tags: ['态势'],
|
||||
responses: { 200: { description: 'events + conflict_stats' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
tags: [{ name: '态势' }, { name: '统计' }, { name: '反馈' }, { name: '调试' }, { name: '系统' }],
|
||||
}
|
||||
Reference in New Issue
Block a user