Closed marsxu1984 closed 10 years ago
You can just combine the case statement into 1 route. See the web socket example project.
V
On 14 Jan 2014, at 4:19 pm, Mars notifications@github.com wrote:
val routes = PartialFunction[SockoEvent, Unit] { case HttpRequest(request) => request match { case GET(Path("/favicon.ico")) => { request.response.write(HttpResponseStatus.NOT_FOUND) } case GET(Path("/index")) => { assetsContentRouter ! new StaticResourceRequest(request, "assets/index.html") } case PathSegments("assets" :: relativePath) => { assetsContentRouter ! new StaticResourceRequest(request, relativePath.mkString("assets/", "/", "")) } } } val webSocketRoutes = PartialFunction[SockoEvent, Unit] { case WebSocketHandshake(wsHandshake) => { authToken(wsHandshake) } case WebSocketFrame(frame) => { Supreme.msgImportHandler ! WebSocketFrameEvent(frame) } }
val webServer = new WebServer( config, Routes(httpRoutes orElse webSocketRoutes), actorSystem )
IF I GOT multiple router, need to be group together,How should I do? — Reply to this email directly or view it on GitHub.
combine the case statement, How to do it, I have no idea...
val routes = Routes({
case HttpRequest(request) => request match {
case GET(Path("/favicon.ico")) => {
request.response.write(HttpResponseStatus.NOT_FOUND)
}
case GET(Path("/index")) => {
assetsContentRouter ! new StaticResourceRequest(request, "assets/index.html")
}
case PathSegments("assets" :: relativePath) => {
assetsContentRouter ! new StaticResourceRequest(request, relativePath.mkString("assets/", "/", ""))
}
}
case WebSocketHandshake(wsHandshake) => {
authToken(wsHandshake)
}
case WebSocketFrame(frame) => {
Supreme.msgImportHandler ! WebSocketFrameEvent(frame)
}
})
An alternative you might want to try is:
val combinedRoutes = Routes(routes, webSocketRoutes)
See documentation http://sockoweb.org/docs/0.4.1/api/#org.mashupbots.socko.routes.Routes$