UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

5      

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

5      

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

5      

Have you tried changing the hostname to 0.0.0.0?

6      

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/

5      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.