sauliusgrigaitis / Swifton

A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X
MIT License
1.97k stars 69 forks source link

Router not returning assets that aren't text #28

Open califrench opened 8 years ago

califrench commented 8 years ago

This is kind of the same as #25 but that issue encompassed two issues:

  1. All static files were returned in a response with a "text/plain" mimeType -> Now fixed
  2. Media assets can't be returned because the following line failed
// Router.swift:111
...
if let body = String(data:contents!, encoding: NSUTF8StringEncoding) {
...

Any file that is a jpeg or png etc... Returns a nil body on this line which leads to this code returning a notFound Response:

// Router.swift:95
if let staticFile = serveStaticFile(newRequest) {
    return staticFile as! Response
}

return notFound(newRequest) as! Response

So we are still having an issue with not returning media assets this isn't in line with the README

Static assets (JavaScript, CSS, images etc.) are loaded from Public directory by default This is crucial and needs to be fixed before Swifton can be useful. I can't imagine a website without any media assets!

I'm willing to investigate this much further but we may need to modify the router to return ResponseTypes from the router instead of Inquiline Response types... Of course any other thoughts are welcome!

califrench commented 8 years ago

Looks like release 0.3.2 of Inquiline changed the way Responses work and now support PayloadConvertible objects instead of plain strings for the body.