2

I am trying to set up Swagger in a VM/Vagrant box. What I have done is below.

i. Port Forwarding using Vagrantfile

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

ii. Swagger configuration in a vagrant box

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

I tried to open Swagger Editor with command swagger project edit -p 3000 -s, which gives

Starting Swagger Editor. Running Swagger Editor API server. You can make GET and PUT calls to http://127.0.0.1:3000/editor/spec

Seems like everything is perfect so just visited browser of local desktop(windows), and visited http://localhost:3000/editor/spec which gives me This site can’t be reached.

curl http://localhost:3000/editor/spec is working fine in the VM/vagrant box.

What wrong am I doing here?

Deamon
  • 109
  • 3
  • 10

1 Answers1

2

The issue is

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.

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • Yes, it's working now but not opening actual editor just like some text. Do you know why? – Deamon Jul 10 '17 at 06:23
  • what you mean "just like some text" - don't you get https://github.com/swagger-api/swagger-node/blob/master/docs/cli.md#swagger-project-edit-options-directory ? maybe you should create new question with the details and actual vs expected result – Frederic Henri Jul 10 '17 at 07:01
  • Can you please take a look at it here(https://stackoverflow.com/questions/45005086/swagger-editor-isnt-opening-in-chrome-version-59-0-3071-115-official-build-6)? The same thing in Windows is working just fine. I mean, I can see the exact window shown in there. But what's wrong going with a virtual machine set using vagrant? – Deamon Jul 10 '17 at 08:47