Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm: load the cascade files from the local env.
- Loading branch information
Showing
6 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
all: | ||
all: | ||
@./build.sh | ||
clean: | ||
@rm -f pigo | ||
install: all | ||
@cp pigo /usr/local/bin | ||
uninstall: | ||
uninstall: | ||
@rm -f /usr/local/bin/pigo | ||
package: | ||
@NOCOPY=1 ./build.sh package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ wasm: | |
|
||
serve: | ||
$(BROWSER) 'http://localhost:5000' | ||
serve | ||
go run http/serve.go | ||
|
||
clean: | ||
rm -f *.wasm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"path/filepath" | ||
) | ||
|
||
// httpConn web server connection parameters | ||
type httpConn struct { | ||
address string | ||
port string | ||
root string | ||
cascadeDir string | ||
} | ||
|
||
func main() { | ||
httpConn := &httpConn{ | ||
address: "localhost", | ||
port: "5000", | ||
root: "./", | ||
cascadeDir: "../cascade/", | ||
} | ||
c := NewConn(httpConn) | ||
c.Init() | ||
} | ||
|
||
// NewConn establish a new http connection | ||
func NewConn(conn *httpConn) *httpConn { | ||
return conn | ||
} | ||
|
||
// Init listen and serves the connection endpoints | ||
func (c *httpConn) Init() { | ||
var err error | ||
c.root, err = filepath.Abs(c.root) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
log.Printf("serving %s on %s:%s", c.root, c.address, c.port) | ||
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(c.root)))) | ||
http.Handle("/cascade/", http.StripPrefix("/cascade/", http.FileServer(http.Dir(c.cascadeDir)))) | ||
|
||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
log.Print(r.RemoteAddr + " " + r.Method + " " + r.URL.String()) | ||
http.DefaultServeMux.ServeHTTP(w, r) | ||
}) | ||
httpServer := http.Server{ | ||
Addr: c.address + ":" + c.port, | ||
Handler: handler, | ||
} | ||
err = httpServer.ListenAndServe() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} |