简体   繁体   中英

before in Kotlin

I'm trying to set a before filter without a path to apply to all requests. In kotlin I'm trying to write:

before { req, resp -> 
    // check auth then redirect if not authorized... 
}

The compiler says:

Cannot infer type for this parameter (req & resp).

How should I set a before filter in Kotlin without a route?

You can use the path * in Spark to match all paths, like this:

before("*", { req, res ->
    logger.info("${req.requestMethod().toUpperCase()} ${req.fullUri()} by ${req.ip()} (${req.userAgent()})")
})

// or:

before("*") { req, res -> // ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM