NEW: Learn to build the incredible iOS 15 Weather app today! >>

localhost works on my MacBook, but other local machines cant see me

Forums > Server-side Swift

http://localhost:8080/home works fine on my laptop, but trying to look at it from a browser on my iPhone doesn't work at all. My MacBook is named Aesop, and the sharing setup says other users should be able to connect to http://Aesop.local:8080/home but safari on the iPad, iPhone, and other Macs on the local network just network times out.

I'm guessing that Catalina is getting in the way, somehow, but I haven't been able to figure out just how. Any ideas?

   

@twostraws  Site AdminHWS+

It's possible the macOS firewall is getting in the way, but a better idea is to use your internal IP address – try running ifconfig from the command line and looking for a local IP, such as 192.168.0.1.

   

ifconfig offers up 10.0.0.158, but http://10.0.0.158:8080 doesn't work either.

stackoverflow suggests that I use this bit of code in configure.swift:

// Define Hostname & Port to listen to ...
let myServerConfig = NIOServerConfig.default(hostname: "aesop.local", port: 8080)
services.register(myServerConfig)

and that worked! Now I can't see it on my mac when I use localhost, but I can see it fine on my mac (and other local Macs and local iPhones and local iPads) by using aesop.local. every tenticle has to be in exactly the right place for this to work, but it's beautiful when it does!

Does anyone know if it's possible to configure it so that both "aesop.local" and "localhost" work from my mac? it's not a big deal, but it could be handy for serving seperate websites from the same vapor server... or maybe I'm just getting ahead of myself :)

   

Have you tried changing the hostname to 0.0.0.0?

   

For the benefit of anyone using Vapor 4, the syntax is completely different. In configure.swift, add this to func configure(_ app: Application):

app.http.server.configuration.hostname = "aesop.local" 
app.http.server.configuration.port = 8080

https://docs.vapor.codes/4.0/server/

   

I've used Vapor 4 before and yes the syntax is completely different. I tried to do it like this, everything worked out.

Regards IT developer staff monitoring

   

Hacking with Swift is sponsored by Essential Developer

SPONSORED Only until this Sunday, December 12th, you can join a free crash course to learn advanced techniques for testing new and legacy Swift code — it's the fast track to becoming a complete Senior iOS Developer!

Click to learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.