1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: run app.init() once

This commit is contained in:
Alexander Medvednikov 2019-08-02 05:54:40 +02:00
parent 8ecd62e56f
commit 81da1f1ab2

View File

@ -88,6 +88,8 @@ $html
pub fn run<T>(port int) { pub fn run<T>(port int) {
println('Running vweb app on http://localhost:$port ...') println('Running vweb app on http://localhost:$port ...')
l := net.listen(port) or { panic('failed to listen') return } l := net.listen(port) or { panic('failed to listen') return }
mut app := T{}
app.init()
for { for {
conn := l.accept() or { conn := l.accept() or {
panic('accept() failed') panic('accept() failed')
@ -138,16 +140,15 @@ pub fn run<T>(port int) {
method: vals[0] method: vals[0]
url: vals[1] url: vals[1]
} }
mut app := T{ //mut app := T{
vweb: Context{ app.vweb = Context{
req: req req: req
conn: conn conn: conn
post_form: map[string]string{} post_form: map[string]string{}
static_files: map[string]string{} static_files: map[string]string{}
static_mime_types: map[string]string{} static_mime_types: map[string]string{}
}
} }
app.init() //}
if req.method == 'POST' { if req.method == 'POST' {
app.vweb.parse_form(s) app.vweb.parse_form(s)
} }