Compare commits
No commits in common. "6e6f8fb741de3573b568f3691cdf210d3577b4c7" and "2619cb9e062b92f42ad86deab0a051cbfb746be4" have entirely different histories.
6e6f8fb741
...
2619cb9e06
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -9,7 +9,7 @@
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/scripts/dev-server/",
|
||||
"program": "${workspaceFolder}/scripts/dev-server/devserver.go",
|
||||
"env": {
|
||||
"GOOS": "windows",
|
||||
"GOARCH": "amd64"
|
||||
|
||||
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module git.d3nexus.de/Dadido3/D3vugu-components
|
||||
|
||||
go 1.25
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/vugu/vgrouter v0.0.0-20200725205318-eeb478c42e5d
|
||||
|
||||
@ -16,14 +16,11 @@ func main() {
|
||||
simplehttp.DefaultStaticData["Title"] = "D3vugu-components examples"
|
||||
simplehttp.DefaultStaticData["CSSFiles"] = []string{"/static/css/d3c-theme-base.css"}
|
||||
|
||||
var wasmHandler WASMExecHandler
|
||||
|
||||
wd, _ := os.Getwd()
|
||||
uiDir := filepath.Join(wd)
|
||||
l := ":8875"
|
||||
log.Printf("Starting HTTP Server at %q", l)
|
||||
h := simplehttp.New(uiDir, true)
|
||||
http.Handle("/wasm_exec.js", &wasmHandler) // A hack to circumvent the old hardcoded path in simplehttp. TODO: Seek alternative to the simplehttp dev server
|
||||
http.Handle("/", h)
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(filepath.Join(uiDir, "static")))))
|
||||
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WASMExecHandler struct {
|
||||
wasmExecJsOnce sync.Once
|
||||
wasmExecJsContent []byte
|
||||
wasmExecJsTs time.Time
|
||||
}
|
||||
|
||||
func (h *WASMExecHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
b, err := exec.Command("go", "env", "GOROOT").CombinedOutput()
|
||||
if err != nil {
|
||||
http.Error(w, "failed to run `go env GOROOT`: "+err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
h.wasmExecJsOnce.Do(func() {
|
||||
h.wasmExecJsContent, err = os.ReadFile(filepath.Join(strings.TrimSpace(string(b)), "lib/wasm/wasm_exec.js"))
|
||||
if err != nil {
|
||||
http.Error(w, "failed to run `go env GOROOT`: "+err.Error(), 500)
|
||||
return
|
||||
}
|
||||
h.wasmExecJsTs = time.Now() // hack but whatever for now
|
||||
})
|
||||
|
||||
if len(h.wasmExecJsContent) == 0 {
|
||||
http.Error(w, "failed to read wasm_exec.js from local Go environment", 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
http.ServeContent(w, r, "/wasm_exec.js", h.wasmExecJsTs, bytes.NewReader(h.wasmExecJsContent))
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user