馃 A practical web framework for Gleam
at main 25 lines 706 B view raw
1import wisp 2import tiny_database 3 4// A new Context type, which holds any additional data that the request handlers 5// need in addition to the request. 6// 7// Here it is holding a database connection, but it could hold anything else 8// such as API keys, IO performing functions (so they can be swapped out in 9// tests for mock implementations), configuration, and so on. 10// 11pub type Context { 12 Context(db: tiny_database.Connection) 13} 14 15pub fn middleware( 16 req: wisp.Request, 17 handle_request: fn(wisp.Request) -> wisp.Response, 18) -> wisp.Response { 19 let req = wisp.method_override(req) 20 use <- wisp.log_request(req) 21 use <- wisp.rescue_crashes 22 use req <- wisp.handle_head(req) 23 24 handle_request(req) 25}