| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | import databases |
| 5 | import os |
| 6 | |
| 7 | const port = 8082 |
| 8 | |
| 9 | pub struct Context { |
| 10 | veb.Context |
| 11 | } |
| 12 | |
| 13 | struct App { |
| 14 | veb.StaticHandler |
| 15 | } |
| 16 | |
| 17 | pub fn (app &App) before_request(mut ctx Context) { |
| 18 | println('[veb] before_request: ${ctx.req.method} ${ctx.req.url}') |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | mut db := databases.create_db_connection() or { panic(err) } |
| 23 | |
| 24 | sql db { |
| 25 | create table User |
| 26 | create table Product |
| 27 | } or { panic('error on create table: ${err}') } |
| 28 | |
| 29 | db.close() or { panic(err) } |
| 30 | |
| 31 | mut app := &App{} |
| 32 | app.serve_static('/favicon.ico', 'assets/favicon.ico') or { panic(err) } |
| 33 | app.mount_static_folder_at(os.resource_abs_path('.'), '/') or { panic(err) } |
| 34 | |
| 35 | veb.run[App, Context](mut app, port) |
| 36 | } |
| 37 | |
| 38 | pub fn (mut app App) index(mut ctx Context) veb.Result { |
| 39 | title := 'veb app' |
| 40 | |
| 41 | return $veb.html() |
| 42 | } |
| 43 | |