0

Is it possible to host a local server with a custom hostname in iOS?

I am trying to create an app that needs a requirement for a local server, I tried different libraries to host a local server like GCDWebServer and Telegraph. But none of the libraries has an option to provide a custom interface name.

Instead of http://localhost:4000/home, I would like to have http://mybookslibrary.com/home

Is it possible? Is there any library that supports to achieve this behavior?

Perseus
  • 1,546
  • 4
  • 30
  • 55
  • I don't understand your request – dbenitobaldeon Jun 09 '20 at 15:51
  • @dbenitobaldeon, I wanted to host a local server in iOS with a custom host name – Perseus Jun 09 '20 at 15:52
  • Do you have control over the `mybookslibrary.com` domain? – Rudedog Jun 09 '20 at 16:01
  • This isn't a function of the server; it is the name resolution used by the operating system. On a Mac or PC you could edit the `hosts` file to point some other host name to 127.0.0.1 but there is no access to the hosts file on iOS. As Rudedog says, if you control the domain you want to use you can make the required host name an A record for 127.0.0.1 – Paulw11 Jun 09 '20 at 21:10
  • @Paulw11, No I don't have control over the domain. What I really wanted to do is host a local server with different hostnames (even if I could set up a proxy). I am not sure whether its possible, that's why I am reaching out to you guys – Perseus Jun 10 '20 at 01:49
  • This doesn't really sound like something that would be applicable for an iOS app. A local web server only runs while the app is in the foreground and the device is unlocked. You could use Bonjour to advertise a server on the local network so that other devices could find it. Other apps on the same device won't be able to connect to a local server since the server won't run while another app is in the foreground – Paulw11 Jun 10 '20 at 01:56
  • @Paulw11, You are right. I just want to start the local server for my iOS app only not other apps. And I understand the local server will be available If my app is in the foreground & unlocked. I am looking for a way to use a custom Bonjour name for my local server. – Perseus Jun 10 '20 at 04:15
  • Right, well you can't really. Why would it matter if it only your app accessing the server within itself. Indeed, why would you even use a server? – Paulw11 Jun 10 '20 at 04:20
  • @Paulw11, I am downloading 10 folders under application Document path and each folder has its own HTML,JS, web components files. Now I am trying to load each folder in WKWebView using webView.load(urlRequest) and I see the data separation (local storage) is not achieved using this approach, all folders share the same WKWebViewDataStore. Now to overcome this issue, I wanted to host a local server that would be like every folder will have its own hostname and the data separation can be achieved. – Perseus Jun 10 '20 at 04:26
  • @Paulw11, I also tried using WKURLSchemeHandler which is actually a workaround for this solution but again I had some issues with integrating the Analytics which forced to look for possible local server solution – Perseus Jun 10 '20 at 04:27
  • @Perseus were you able to create a local server, I need to do same!, thanks in advance – user1068810 Mar 06 '21 at 14:58
  • did you achieve this by using custom domain? if yes, can you please provide us your solution as a answer? – Ganesh G Apr 11 '23 at 06:24

0 Answers0