diff --git a/examples/http_read.vqe b/examples/http_read.vqe index 3b50890..149cdaa 100644 --- a/examples/http_read.vqe +++ b/examples/http_read.vqe @@ -1,3 +1,4 @@ { -"examples/test.html" readall disp + "examples/test.html" readall disp + argv shatter dump } ":3333" servehttp diff --git a/examples/webassembly-example/server.vqe b/examples/webassembly-example/server.vqe index 0b216e3..7eaca94 100644 --- a/examples/webassembly-example/server.vqe +++ b/examples/webassembly-example/server.vqe @@ -1,3 +1,13 @@ { - "index.html" readall disp + (* get the request info *) + argv shatter + + (* check to see if we have the root route, if so return index.html *) + dup "/" streq? + choose + { exch pop "index.html" exch } ifyes + { "." exch strtie } ifno + + (* now read the requested file and return it *) + readall disp } ":3333" servehttp diff --git a/varaq/interpreter.go b/varaq/interpreter.go index 740a6f8..665149c 100644 --- a/varaq/interpreter.go +++ b/varaq/interpreter.go @@ -5,12 +5,12 @@ import ( "fmt" "io" "io/ioutil" - "runtime" "math" "math/rand" "net" "net/http" "os" + "runtime" "strconv" "strings" "time" @@ -1064,15 +1064,20 @@ func Interpret(code Expr, argv []string, w io.Writer) error { return fmt.Errorf("cannot `servehttp` exptected a string for the port @%v", idx) } + fun, e := pop() + if e != nil { + return e + } + http.ListenAndServe(str.Value.(string), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { req := make([]string, 0) req = append(req, r.RequestURI) - fun, e := pop() - if e != nil { - return - } + if fun.Tok == FUNCTION { - Interpret(fun, req, w) + zerr := Interpret(fun, req, w) + if zerr != nil { + fmt.Println(zerr) + } } else { return }