以下是在Ubuntu上部署Swagger UI的几种方法:
sudo apt update,sudo apt install docker.io。docker pull swaggerapi/swagger-ui-express。docker run -p 8080:8080 swaggerapi/swagger-ui-express。http://localhost:8080。sudo apt update,sudo apt install nodejs npm。mkdir swagger-ui-project,cd swagger-ui-project,npm init -y。npm install swagger-ui-express。app.js文件,添加代码:const express = require('express'); const swaggerUi = require('swagger-ui-express'); const YAML = require('yamljs'); const swaggerDocument = YAML.load('./swagger.yaml'); const app = express(); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(Server is running on port ${PORT}); });。swagger.yaml文件,添加API文档。node app.js,访问http://localhost:3000/api-docs。