| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import veb |
| 5 | |
| 6 | const http_port = 3001 |
| 7 | const vexe = os.quoted_path(os.getenv_opt('VEXE') or { @VEXE }) |
| 8 | |
| 9 | pub struct Context { |
| 10 | veb.Context |
| 11 | } |
| 12 | |
| 13 | pub struct App { |
| 14 | veb.StaticHandler |
| 15 | } |
| 16 | |
| 17 | fn main() { |
| 18 | os.chdir(os.dir(@FILE))! |
| 19 | mut app := &App{} |
| 20 | veb.run_at[App, Context](mut app, port: http_port)! |
| 21 | } |
| 22 | |
| 23 | // before_accept_loop builds draw.js before the server starts and registers the static assets. |
| 24 | pub fn (mut app App) before_accept_loop() { |
| 25 | os.execute_or_panic('${vexe} -b js_browser draw.js.v') |
| 26 | app.serve_static('/draw.js', 'draw.js') or { panic(err) } |
| 27 | app.serve_static('/index.html', 'index.html') or { panic(err) } |
| 28 | } |
| 29 | |