v / examples / js_dom_draw / main.v
28 lines · 22 sloc · 633 bytes · 8dcb9f9fcac38a51d0e2514fbf2b63e23d2b7ef0
Raw
1module main
2
3import os
4import veb
5
6const http_port = 3001
7const vexe = os.quoted_path(os.getenv_opt('VEXE') or { @VEXE })
8
9pub struct Context {
10 veb.Context
11}
12
13pub struct App {
14 veb.StaticHandler
15}
16
17fn 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.
24pub 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