fix the http listener

This commit is contained in:
zongor 2024-07-12 22:15:00 -04:00
parent 9d4cc1ff09
commit 81b765a1b2
3 changed files with 24 additions and 8 deletions

View File

@ -1,3 +1,4 @@
{
"examples/test.html" readall disp
"examples/test.html" readall disp
argv shatter dump
} ":3333" servehttp

View File

@ -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

View File

@ -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
}