我有很多API路由,并且所有这些路由都使用此函数来添加标题:
def jsonRoute(fn: => ToResponseMarshallable, method: Directive0 = get): Route = method {
val jsonResponse = respondWithMediaType(`application/json`) {
complete(fn)
}
if (corsAllowed) respondWithHeader(RawHeader("Access-Control-Allow-Origin", "*"))(jsonResponse)
else jsonResponse
}
现在我从喷雾迁移到akka-http,而responseWithMediaType在那里被视为反模式。如何在不改变它的界面的情况下重写这个功能?