14

I have a web app developed using server side swift vapor 3 running locally on my Mac. I want to access it using my iPhone on the same wifi as my Mac. How can I do that. I tried using http://<the ip of my Mac on local network>:8080 but didn't work, even with firewall completely off. Thanks in advance.

3 Answers3

15

Edit you Run scheme in Xcode and put --hostname 0.0.0.0 --port 8080 into Arguments Passed On Launch

enter image description here

enter image description here

Then launch you server and try to reach it by http://<the ip of your Mac on local network>:8080

NOTE: 0.0.0.0 means that your server will listen on all network interfaces

imike
  • 5,515
  • 2
  • 37
  • 44
  • On phone doesn't show up. I get these two in the console. [si_destination_compare] send failed: Invalid argument [si_destination_compare] send failed: Undefined error: 0 –  Jun 14 '19 at 18:48
  • 1
    I tried again, it seems that the router was the problem and it worked. thanks. –  Jun 14 '19 at 19:43
15

Add the keyword 'serve' for vapor 4.

enter image description here

lukaskasa
  • 498
  • 1
  • 8
  • 12
7

Does it have to be over your local wifi? If not, I would suggest you to use services like https://ngrok.com/ It will expose Vapor port 8080 to the internet and you will be able to access it on your iPhone app, even over the LTE connection.

Simply run: ngrok http 8080. It will forward all of the traffic, for example:

Forwarding                    http://24ab019e.ngrok.io -> http://localhost:8080                                                                
Forwarding                    https://24ab019e.ngrok.io -> http://localhost:8080    
Mike Mikina
  • 496
  • 4
  • 13