PerfectlySoft / Perfect

Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
https://www.perfect.org
Apache License 2.0
13.84k stars 945 forks source link

Routing not working on Linux #181

Open nsleader opened 8 years ago

nsleader commented 8 years ago

If HTTP server load the module containing the routes dynamically (via PerfectLibraries/*.so), the routing does not work.

(Perfect 0.19)

Example: https://github.com/nsleader/perfect-routing-linux Сhecked on: Ubuntu 14.04, swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a.xctoolchain

ShaneQi commented 8 years ago

try

...
Routing.Routes["GET", ["/", "index.html"]] = indexHandler
...
nsleader commented 8 years ago

@ShaneQi did not help

nsleader commented 8 years ago

I realized what the problem is. struct RouteMap in server executable package and struct RouteMap in Site library package is different instances!

@kjessup what do you think?

syky27 commented 8 years ago

@nsleader Hey! It works for me with following example:

import PerfectLib

public func PerfectServerModuleInit(){
    Routing.Handler.registerGlobally()
    Routing.Routes["GET", ["/", "index.html"]] = { (_:WebResponse) in return IndexHandler() }
    Routing.Routes["POST", "/post"] = { _ in return PostHandler() }

}

class IndexHandler: RequestHandler {
    func handleRequest(request: WebRequest, response: WebResponse) {
        response.appendBodyString("Hello Perfect")
        response.requestCompletedCallback()
    }
}

class PostHandler: RequestHandler {
    func handleRequest(request: WebRequest, response: WebResponse) {
        response.appendBodyString("\(request.postBodyString)")
        response.requestCompletedCallback()
    }
}

IMHO you are passing handler to Routes incorrectly...

nsleader commented 8 years ago

@syky27 I used latest Perfect version of master branch. There's no Routing.Handler.registerGlobally()

I understand what the problem is, but I do not have time to implement solutions

syky27 commented 8 years ago

@nsleader ok, I see.

ShaneQi commented 8 years ago

I'm not sure if the latest Perfect version is bug-free. I just personal prefer release version, even thought there are bugs.

However, you probably want to check out this example: https://github.com/PerfectlySoft/PerfectExample-URLRouting/tree/89531476853af89da7f8367545936d984264e360

It was updated 6 days ago, and I think this example works well on latest Perfect.

nsleader commented 8 years ago

@ShaneQi I do not think it's a bug. I think that this behavior is simply not provided.

If you add the routes from the module other than the server module, there is a problem: Server module will not see this route as it is different scope.

I can not use the release version for this reason: https://github.com/PerfectlySoft/Perfect/issues/179

Sorry for my English.

iamjono commented 8 years ago

@nsleader can you clarify which version of the PerfectLib that you are using? (No need to apologize for your English -it's fine :))