fix the http listener
This commit is contained in:
		
							parent
							
								
									9d4cc1ff09
								
							
						
					
					
						commit
						81b765a1b2
					
				| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
"examples/test.html" readall disp
 | 
					    "examples/test.html" readall disp
 | 
				
			||||||
 | 
					    argv shatter dump
 | 
				
			||||||
} ":3333" servehttp
 | 
					} ":3333" servehttp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
					} ":3333" servehttp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,12 +5,12 @@ import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"runtime"
 | 
					 | 
				
			||||||
	"math"
 | 
						"math"
 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"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)
 | 
									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) {
 | 
								http.ListenAndServe(str.Value.(string), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
				req := make([]string, 0)
 | 
									req := make([]string, 0)
 | 
				
			||||||
				req = append(req, r.RequestURI)
 | 
									req = append(req, r.RequestURI)
 | 
				
			||||||
				fun, e := pop()
 | 
					
 | 
				
			||||||
				if e != nil {
 | 
					 | 
				
			||||||
					return
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				if fun.Tok == FUNCTION {
 | 
									if fun.Tok == FUNCTION {
 | 
				
			||||||
					Interpret(fun, req, w)
 | 
										zerr := Interpret(fun, req, w)
 | 
				
			||||||
 | 
										if zerr != nil {
 | 
				
			||||||
 | 
											fmt.Println(zerr)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue