From 3cd9e2cab7cd3679df697a46d12d783d6dca52ab Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Sun, 5 Jul 2020 22:05:58 +0200 Subject: [PATCH] vweb: fix index (#5682) --- examples/vweb/vweb_assets/main.v | 2 +- vlib/vweb/vweb.v | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/vweb/vweb_assets/main.v b/examples/vweb/vweb_assets/main.v index fd6b49f379..c21eef83d4 100644 --- a/examples/vweb/vweb_assets/main.v +++ b/examples/vweb/vweb_assets/main.v @@ -29,7 +29,7 @@ pub fn (mut app App) init_once() { pub fn (mut app App) init() {} -fn (mut app App) index() { +pub fn (mut app App) index() { // We can dynamically specify which assets are to be used in template. mut am := assets.new_manager() am.add_css('assets/index.css') diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index ae73a4c1c1..af072e3f78 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -346,6 +346,13 @@ fn handle_conn(conn net.Socket, mut app T) { // since such methods have a priority. // For example URL `/register` matches route `/:user`, but `fn register()` // should be called first. + + if url_words.len == 0 { + app.index() + conn.close() or {} + return + } + println('no attrs for ${url_words[0]}') if url_words[0] == method { println('easy match $method')