migrado de js para go

This commit is contained in:
Luiz Silva 2026-01-01 19:32:29 -03:00
parent 663a8d5bf2
commit 6f78511946
7 changed files with 964 additions and 83 deletions

View file

@ -92,6 +92,38 @@ func main() {
http.ServeFile(w, r, "web/static/e-li.nps.js")
})
// WASM do widget.
// Regra: cache controlado por ETag e revalidação obrigatória.
// Importante: mantemos o MESMO ETag da inicialização (versaoWidget)
// para JS e WASM, garantindo que ambos "andem juntos".
r.Get("/e-li.nps.wasm", func(w http.ResponseWriter, r *http.Request) {
etag := fmt.Sprintf("\"%s\"", versaoWidget)
w.Header().Set("ETag", etag)
w.Header().Set("Cache-Control", "no-cache, must-revalidate")
w.Header().Set("Content-Type", "application/wasm")
if r.Header.Get("If-None-Match") == etag {
w.WriteHeader(http.StatusNotModified)
return
}
http.ServeFile(w, r, "web/static/e-li.nps.wasm")
})
// Runtime JS do Go para WASM.
// Também fica sob ETag + revalidação.
r.Get("/wasm_exec.js", func(w http.ResponseWriter, r *http.Request) {
etag := fmt.Sprintf("\"%s\"", versaoWidget)
w.Header().Set("ETag", etag)
w.Header().Set("Cache-Control", "no-cache, must-revalidate")
w.Header().Set("Content-Type", "application/javascript")
if r.Header.Get("If-None-Match") == etag {
w.WriteHeader(http.StatusNotModified)
return
}
http.ServeFile(w, r, "web/static/wasm_exec.js")
})
r.Handle("/*", http.StripPrefix("/static/", fileServer))
})
// Conveniência: permitir /teste.html