BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

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?

1      

@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.

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 :)

1      

Have you tried changing the hostname to 0.0.0.0?

2      

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/

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.