Static pages broken?
static files appear not to be getting served:
let server = HttpServer()
server["/files/:path"] = directoryBrowser( PublicDir )
do {
let port = 8082
try server.start( in_port_t(port) )
print( "HTTP Server started on \(port)")
} catch {
print( "failed to start web server \(error)" )
}
Browse to http://localhost:8082/files and see a correct list of files and directories. Click on an html file and I get an empty page.
Browse to http://localhost:8082/files/test.html, where test.html exists. Again, I get an empty page.
Thoughts appreciated.
Anyone have thoughts on this? Am I missing something obvious?
What HTTP response code do you get on the http://localhost:8082/files/test.html: 200, 400 or 500 ? Did you check file permissions ?
I can see in https://github.com/httpswift/swifter/blob/b33295680aea4fae0d88f07024da35b4d9f33ca2/Sources/Files.swift#L41 that if a read error occurs, it is currently ignored. It should return something appropriate, like a 403 on permission error.
File permissions checked right through the tree, set to 0777 while testing. I'm struggling to find a response code anywhere.
I did find that. the closure, return { r in ... in shareFilesFromDirectory() isn't getting called at all. Currently trying to figure out why that may be.
I did find that. the closure,
return { r in ...inshareFilesFromDirectory()isn't getting called at all. Currently trying to figure out why that may be.
My bad, I was misunderstanding the way this was working.
writer.write( file ) on line 41 throws an error; "sendfile: Operation not permitted". test.html is in '/Users/kimaldis/Library/Containers/com.kim-aldis.EarwigServer/Data/htdocs'. The file has 0777 permissions as does the tree leading up to it. I'm serving from this folder, returned by NSHomeDirectory() + "/htdocs" because App Sandboxing, which seems to be new in Mojave/Xcode 10, wasn't allowing me to serve from much of anywhere else. I've enabled network incoming and outgoing access but there doesn't seem to be much else obvious there to try. Digging continues.
sendfile() is returning -1 in Socket, line 45 of Socket+File.swift. As I said, I have Incoming & Outgoing connections enabled in the App Sandbox and all file permissions are good. I'm not sure where else I might look.
This is Mojave, Xcode 10, btw.
I think I've found it. sendfile() at line 45 of Socket+File.swift fails but using sendfileImpl() instead seems to work. I changed two lines in Socket+File.swift:
Line 10 #if os(iOS) || os(tvOS) || os (Linux) || os (macOS)
and
Line 42 #if os(iOS) || os(tvOS) || os (Linux) || os (macOS)
My understanding of sockets isn't good enough that I can be sure what's going on or, indeed, that this won't have unwanted side effects but it's working for now.
This also fixes the problem I was having with directoryBrowser().
Thanks, Marc, for the input, it got me to the right place.
Hey @Vkt0r - I'm just having this exact issue right now, and was wondering if there's any chance of making this change? It does seem that sendFile() is not permitted when app sandboxing is enabled. Is there a reason not to use sendfileImpl() for macOS?