PerfectlySoft / Perfect-HTTP

Base HTTP Support for Perfect.
https://www.perfect.org
Apache License 2.0
31 stars 34 forks source link

Modify request static file path in StaticFileHandler #6

Closed xielibin closed 7 years ago

iamjono commented 8 years ago

Thanks @xielibin - could you submit a use case where this is an issue please?

xielibin commented 8 years ago

@iamjono

First, clone PerfectTemplate project and add

routes.add(method: .get, uri: "/**", handler: {
    request, response in
    StaticFileHandler(documentRoot: request.documentRoot).handleRequest(request: request, response: response)
})

to main.swift file.

Second, build PerfectTemplate and launch project, add a test.html file to ./webroot directory. Next, request http://localhost:8181/test.html, then the func handleRequest in StaticFileHandler

var path = request.path

the path is "/test.html" and documentRoot is "./webroot", so 'documentRoot + "/" + path' is "./webroot//test.html", the file will not be found.