This commit is contained in:
Penguin-71630
2025-12-07 16:52:09 +08:00
commit ec986f2dbf
5 changed files with 447 additions and 0 deletions

28
api/view-API-doc.js Normal file
View File

@@ -0,0 +1,28 @@
const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const path = require('path');
// 設定你的 yaml 檔案路徑
// 假設這個 js 檔在根目錄,而 yaml 在 api 資料夾內
const filePath = path.join(__dirname, 'openapi.yml');
try {
// 嘗試讀取檔案
const swaggerDocument = YAML.load(filePath);
// 設定路由
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
console.log('==================================================');
console.log(`文件伺服器已啟動!`);
console.log(`請用瀏覽器打開: http://localhost:3000/docs`);
console.log('==================================================');
} catch (e) {
console.error("讀取 yaml 檔案失敗,請檢查路徑是否正確:", filePath);
console.error(e);
}
app.listen(3000);