diff --git a/src/gitly.v b/src/gitly.v index ece88086..02391037 100644 --- a/src/gitly.v +++ b/src/gitly.v @@ -23,6 +23,7 @@ const namechange_period = time.hour * 24 @[heap] pub struct App { veb.StaticHandler + veb.Middleware[Context] started_at i64 pub mut: db sqlite.DB @@ -131,6 +132,7 @@ pub fn (mut app App) init_server() { } pub fn (mut app App) before_request(mut ctx Context) { + url := ctx.req.url ctx.logged_in = app.is_logged_in(mut ctx) app.load_settings() @@ -141,6 +143,7 @@ pub fn (mut app App) before_request(mut ctx Context) { User{} } } + dump(url) } @['/'] diff --git a/src/main.v b/src/main.v index f38b405c..5af48d6e 100644 --- a/src/main.v +++ b/src/main.v @@ -12,6 +12,8 @@ fn main() { return } mut app := new_app()! + + app.use(handler: app.before_request) // vweb.run_at(new_app()!, http_port) veb.run_at[App, Context](mut app, port: http_port, family: .ip, timeout_in_seconds: 2) or { diff --git a/src/user_routes.v b/src/user_routes.v index 3bffdd6b..61179a50 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -12,7 +12,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { ctx.set_cookie(name: 'csrf', value: csrf) if app.is_logged_in(mut ctx) { - return ctx.not_found() + return ctx.redirect("/" + ctx.user.username) } return $veb.html()