如何重定向 lift 框架中的所有未知 URL?

How can I redirect all unknown URLs in lift framework?

我对 lift 框架不是很熟悉,想知道使用 lift 框架是否可以实现以下用例。

在服务器 1 上,Lift 在以下 url“/contact/”

处提供 REST 网络服务

但是,如果客户端发送请求到下面URL https://server1/contact/meet/" then it is not implemented on this specific server but "might" be implemented by another server. Can Lift redirect any such unsupported URLs to some specific server? Eg, in 302 response, can Location be specified by Lift to https://server2/contact/meet/

请注意,这些是未知的 URL,无法静态配置。

是的,我明白了。也许您需要 LiftRules.dispatchnet.liftweb.http.DoRedirectResponse。以下是我尝试解决您的问题的代码。

// The code should in the server1; JsonDSL will be used by JsonResponse
class Boot extends Bootable with JsonDSL {
   def boot {
       initDispatch
   }


   def initDispatch {
      LiftRules.dispatch.append { 

        case Req("contact" :: url :: Nil, _, GetRequest) => {
            () => Full(
                if (url == "join") {
                    // or other url that match what will be implemented in server1

                    // your implementation, say JsonResponse
                    JsonResponse("server1" -> true)
                } else {
                    // if the url part does not match simply redirect to server2, 
                   // then you have to deal with how to process the url in server2

                    DoRedirectResponse("https://server2/contact/meet/")
                }
            )
        }
     }
   }
 }

总之,希望对你有所帮助。