Perfect icon indicating copy to clipboard operation
Perfect copied to clipboard

Routing not working on Linux

Open nsleader opened this issue 8 years ago • 9 comments

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

nsleader avatar Jun 01 '16 20:06 nsleader

try

...
Routing.Routes["GET", ["/", "index.html"]] = indexHandler
...

ShaneQi avatar Jun 02 '16 06:06 ShaneQi

@ShaneQi did not help

nsleader avatar Jun 02 '16 06:06 nsleader

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?

nsleader avatar Jun 02 '16 10:06 nsleader

@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...

syky27 avatar Jun 07 '16 21:06 syky27

@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

nsleader avatar Jun 08 '16 05:06 nsleader

@nsleader ok, I see.

syky27 avatar Jun 08 '16 10:06 syky27

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.

ShaneQi avatar Jun 08 '16 16:06 ShaneQi

@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.

nsleader avatar Jun 08 '16 18:06 nsleader

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

iamjono avatar Jun 22 '16 14:06 iamjono