sauliusgrigaitis / Swifton

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

Files in public directory being opened as UTF8 Strings #25

Closed califrench closed 8 years ago

califrench commented 8 years ago

I'm trying to load images from the public directory but it seems from looking at the router code that anything loaded from the public directory needs to be source code—like css or js files.

// In Router.swift
if let body = String(data:contents!, encoding: NSUTF8StringEncoding) {
    return Response(.Ok, contentType: "text/plain; charset=utf8", body: body)
}

We should be able to also load images and other assets from that directory. Also CSS files and JS files should return a different mimetype than text/plain.

califrench commented 8 years ago

This issue isn't as simple as writing an else statement and returning a different response since responses must have a body of the following type: String? I'm trying to figure out a solution for this but most likely won't come up with the most graceful one. I'll submit a PR if I think my solution is viable.

sauliusgrigaitis commented 8 years ago

@califrench thanks. I believe there is solution for mime types management in Swift, we should not be very first facing this issue :) Please let me know if you will find something.

califrench commented 8 years ago

@sauliusgrigaitis I realized that this was highlighting two different issues as I typed my explanation up. One issue is the fact we are sending all assets with text/plain but the bigger issue is we can only return text resources and not binary files with a Response

califrench commented 8 years ago

This is no longer an issue. EDIT: I forgot this was referring to files such as images. It is still an issue.

califrench commented 8 years ago

This is a duplicate of #28