完善保险端前后端和养殖端小程序
This commit is contained in:
38
backend/routes/api-docs.js
Normal file
38
backend/routes/api-docs.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* API文档路由
|
||||
* @file api-docs.js
|
||||
* @description 提供Swagger API文档访问
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
const swaggerSpecs = require('../swagger-config');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Swagger UI配置
|
||||
const swaggerUiOptions = {
|
||||
customCss: '.swagger-ui .topbar { display: none }',
|
||||
customSiteTitle: '智能预警系统 API 文档',
|
||||
swaggerOptions: {
|
||||
docExpansion: 'none',
|
||||
defaultModelsExpandDepth: 2,
|
||||
defaultModelExpandDepth: 2,
|
||||
displayRequestDuration: true,
|
||||
filter: true,
|
||||
showExtensions: true,
|
||||
showCommonExtensions: true
|
||||
}
|
||||
};
|
||||
|
||||
// 提供JSON格式的API规范
|
||||
router.get('/swagger.json', (req, res) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(swaggerSpecs);
|
||||
});
|
||||
|
||||
// 提供Swagger UI界面
|
||||
router.use('/', swaggerUi.serve);
|
||||
router.get('/', swaggerUi.setup(swaggerSpecs, swaggerUiOptions));
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user