我在玩Kitura。我已经安装了一台路由器端点,看起来像:通过删除'下一个'关闭来简化Kitura RouterHandler?
let router = Router()
router.all() { _, response, next in
response.headers["Content-Type"] = "application/json; charset=utf-8"
next()
}
router.get("/hello") { _, response, next in
response.send("{\"message\": \"Hello World\"}")
next()
}
Kitura.addHTTPServer(onPort: 9143, with: router)
print("Application Server Starting...")
Kitura.run()
我真的很困惑/这个next
关闭/回调参数受挫。许多(也许过时?)教程没有提及或包含它,但如果我不叫它,我的路由器会挂起,并且客户端响应从不发送。
有没有办法让我避免在我的RouterHandler
中打电话给我?或者让它自动调用?它似乎是潜在的人为错误的一个巨大来源,需要在每种方法中手动执行此回调,并且增加了混乱。 (其他框架如Spring Web自动执行链,不需要next()
调用。)
啊,谢谢 - 我会试试这个。我发现奇怪的是,即使在IBM网站上的教程中不包含'.end()',*或*对next()的调用:https://developer.ibm.com/swift/2016/02/ 22/building-end-end-cloud-apps-using-swift-kitura/ –
我们对Kitura 1.6.1做了一个改变,如果所有的处理程序没有明确结束就结束响应。这应该可以防止其他人遇到你遇到的问题。谢谢! – Navneet