swifter
swifter copied to clipboard
Serving a web content
IMO examples are not enough to start serving a web content. I would like to serve a simple static index.html file. As far as i can see we should call as follows to serve index.html or default.html.
server["/desktop/:path"] = shareFilesFromDirectory("/path/to/index/html")
Now i wonder how do you locate an index.html file in project. If you can, how do you locate index.html in your xcode project at "/path/to/index/html" folder in a simple way. I don't want to serve html content embedded into source code.
Thanks in advance
server["/desktop/:path] = NSHomeDirectory() + "/html"
will serve files from ~/Library/Containers/BundleIdentifier/Data/html
where BundleIdentifier is your project's bundle identifier. NSHomeDIrectory because app sandboxing.
then http://localhost/desktop/index.html
will get you to index.html in your browser, assuming it's in ~/Library/Containers/BundleIdentifier/Data/html
Sandboxing is going to limit where you can serve files from and you may not actually be able to do so from your project. See https://developer.apple.com/app-sandboxing/
That said, I'm still struggling to get files served in this way and I may be missing something obvious.