v2 / examples / wasm / mandelbrot / serve_folder.v
26 lines · 21 sloc · 512 bytes · 4fa8167abbaced0ea99afe662c6ee3a2e2700f40
Raw
1module main
2
3import veb
4import os
5
6pub struct Context {
7 veb.Context
8}
9
10struct App {
11 veb.StaticHandler
12}
13
14fn main() {
15 os.chdir(os.dir(@FILE))!
16 cmd := '${os.quoted_path(@VEXE)} -b wasm -os browser mandelbrot.wasm.v'
17 println('>> compiling mandelbrot.wasm.v, using: ${cmd}')
18 os.execute_or_panic(cmd)
19 mut app := &App{}
20 app.handle_static('.', true)!
21 veb.run[App, Context](mut app, 3001)
22}
23
24pub fn (mut app App) index(mut ctx Context) veb.Result {
25 return ctx.html(os.read_file('mandelbrot.html') or { '' })
26}
27