阅读量:1
以下是在Ubuntu上部署Swagger UI的几种方法:
使用Docker部署
- 安装Docker:
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。
使用Node.js和Express部署
- 安装Node.js和npm:
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。
以上就是关于“Swagger UI在Ubuntu上如何部署”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm