Perfect
Perfect copied to clipboard
Routing not working on Linux
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
try
...
Routing.Routes["GET", ["/", "index.html"]] = indexHandler
...
@ShaneQi did not help
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 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 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 ok, I see.
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 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 can you clarify which version of the PerfectLib that you are using? (No need to apologize for your English -it's fine :))