Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use blue folder containing html files #64

Closed
SamDecrock opened this issue Dec 7, 2015 · 1 comment
Closed

Use blue folder containing html files #64

SamDecrock opened this issue Dec 7, 2015 · 1 comment

Comments

@SamDecrock
Copy link

Hi,

This is not an issue, but I just wanted to let you know that I'm adding complete folders to my Bundle (by adding them as folder, not as group) and then using this code to access them:

server["/public/(.+)"] = directory("HTML/")

func directory(dir: String) -> ( HttpRequest -> HttpResponse ) {
    return { request in
        if let localPath = request.capturedUrlGroups.first {
            print(localPath)
            if let filesPath = NSBundle.mainBundle().pathForResource(dir + localPath, ofType: "") {
                print(filesPath)
                if let fileBody = NSData(contentsOfFile: filesPath) {
                    return HttpResponse.RAW(200, "OK", nil, fileBody)
                }
            }
        }
        return HttpResponse.NotFound
    }
}

Where HTML/ is the blue folder added to my iOS project.

So by going to http://url-to-iphone:port/public/index.html i'm accessing index.html inside the HTML/-folder

@damian-kolakowski
Copy link
Member

hi @SamDecrock

Thanks for the message. Answering to your question, yes, I know about that. It's because of the bundle structure and how iOS build procedure treats resources files. According to https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html all the files are copied to the root of bundle:

A typical iOS application bundle contains the application executable and any resources used by the application (for instance, the application icon, other images, and localized content) in the top-level bundle directory.

best
dk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants