要在Ubuntu上显示Swagger UI,您可以按照以下步骤进行操作:
安装必要的软件包:
sudo apt update
sudo apt install nodejs npm
克隆Swagger UI的git项目:
git clone https://github.com/swagger-api/swagger-ui.git
cd swagger-ui
进入dist
目录并启动HTTP服务器:
cd dist
npm install -g http-server
http-server
在浏览器中访问Swagger UI:
打开浏览器,访问 http://localhost:8080
。
npm install -g swagger-ui
swagger-ui
目录下可能缺少index.html
文件。创建一个新的npm项目:
mkdir temp0620
cd temp0620
npm init -y
安装Express:
npm install express
复制Swagger UI的dist
目录到项目中,并创建index.js
文件:
var express = require('express');
var app = express();
app.use('/root', express.static('dist'));
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
启动服务器并访问Swagger UI:
node index.js
打开浏览器,访问 http://localhost:3000/root/index.html
。
通过以上方法,您可以在Ubuntu上成功显示和使用Swagger UI。如果需要配置特定的Swagger JSON文件,可以在index.js
文件中修改url
参数。