问题描述
我对Lift框架不是很熟悉,想知道以下使用案例是否可以使用Lift框架.
I'm not very familiar with lift framework and wanted to know if the following use case is possible using lift framework.
在server1上,Lift通过以下网址"/contact/"提供REST Web服务
On server1, Lift is serving REST webservice at following url "/contact/"
但是,如果客户端将请求发送到以下URL https://server1/contact/meet/ ",那么它不会在此特定服务器上实现,而是可能"由另一台服务器实现.Lift可以将任何不支持的URL重定向到某个特定服务器吗?例如,在302响应中,Lift可以将位置指定为 https://server2/contact/meet/吗?
However, if the client sends request to the following 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,不能静态配置.
Please note that these are unknown URLs and can't be configured statically.
推荐答案
是的,我明白了.也许您需要 LiftRules.dispatch
和 net.liftweb.http.DoRedirectResponse
.以下是我尝试解决您的麻烦的代码.
Yeah, I get it. Maybe you need LiftRules.dispatch
and net.liftweb.http.DoRedirectResponse
. Following is the code I try to solve your trouble.
// 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/")
}
)
}
}
}
}
无论如何,希望对您有所帮助.
Anyway, hope it helps.
这篇关于如何重定向Lift框架中的所有未知URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!