From 885d7dfbe9e6eeaf1a549fdbf71afcd1402d98cd Mon Sep 17 00:00:00 2001 From: Anton Zavodchikov Date: Tue, 21 Dec 2021 08:51:10 +0500 Subject: [PATCH] Parse middlewares at start --- vlib/vweb/vweb.v | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 06efbfd4f7..5f61ce4e40 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -385,18 +385,24 @@ pub fn run(global_app &T, port int) { mut routes := map[string]Route{} mut middlewares := map[string]string{} $for method in T.methods { + if middleware_path := parse_middleware(method.args, method.attrs) { + middlewares[method.name] = middleware_path + } else { + // There is no `use` attribute, so it returns `none` + if err.str() != 'none' { + eprintln('error parsing `app.$method.name` attributes: $err') + return + } + } + http_methods, route_path := parse_attrs(method.name, method.attrs) or { eprintln('error parsing method attributes: $err') return } - if 'use' in method.attrs.filter(it.len == 3).map(it.to_lower()) { - middlewares[method.name] = route_path - } else { - routes[method.name] = Route{ - methods: http_methods - path: route_path - } + routes[method.name] = Route{ + methods: http_methods + path: route_path } } println('[Vweb] Running app on http://localhost:$port')