2

我正在尝试在 VM/Vagrant 框中设置 Swagger。我所做的如下。

一世。使用 Vagrantfile 进行端口转发

dev.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: 
"127.0.0.1", auto_correct: true

ii. vagrant box 中的 Swagger 配置

npm install -g swagger
Create a new swagger project
swagger project create hello-world

我试图用命令打开 Swagger Editor swagger project edit -p 3000 -s,它给出了

启动 Swagger 编辑器。运行 Swagger Editor API 服务器。您可以对http://127.0.0.1:3000/editor/spec进行 GET 和 PUT 调用

似乎一切都很完美,所以刚刚访问了本地桌面(Windows)的浏览器,并访问了http://localhost:3000/editor/spec这给了我这个站点无法访问。

curl http://localhost:3000/editor/spec在 VM/vagrant 框中工作正常。

我在这里做错了什么?

4

1 回答 1

2

问题是

calls to http://127.0.0.1:3000/editor/spec

so its not accessible on any network interface other than your localhost.

You need to change this to get started the app on the IP of the server or you can use 0.0.0.0 (special IP so all interfaces can access it)

You need to run as

swagger project edit --host 0.0.0.0 -p 3000 -s 

(See the CLI reference guide) - Then you will be able to access from your host at http://localhost:3000

NB: the other option is to assign a static IP either with private network or public network; then start swagger project edit --host <static_ip_from_vagrantfile> -p 3000 -s and access from your host with the static IP and in such case you dont need to forward any port from the guest to the host.

于 2017-07-08T14:01:56.710 回答