mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Update server/main.go to show GopherJS errors
This commit is contained in:
parent
c98631a703
commit
b769e0eb6c
@ -15,8 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -61,8 +63,10 @@ func createJSIfNeeded(name string) (string, error) {
|
|||||||
}
|
}
|
||||||
if (err != nil && os.IsNotExist(err)) || time.Now().Sub(stat.ModTime()) > 10*time.Second {
|
if (err != nil && os.IsNotExist(err)) || time.Now().Sub(stat.ModTime()) > 10*time.Second {
|
||||||
target := "github.com/hajimehoshi/ebiten/example/" + name
|
target := "github.com/hajimehoshi/ebiten/example/" + name
|
||||||
if err := exec.Command("gopherjs", "build", "-o", out, target).Run(); err != nil {
|
out, err := exec.Command("gopherjs", "build", "-o", out, target).CombinedOutput()
|
||||||
return "", err
|
if err != nil {
|
||||||
|
log.Print(string(out))
|
||||||
|
return "", errors.New(string(out))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
@ -97,19 +101,22 @@ func appName(r *http.Request) (string, error) {
|
|||||||
func serveMainJS(w http.ResponseWriter, r *http.Request) {
|
func serveMainJS(w http.ResponseWriter, r *http.Request) {
|
||||||
name, err := appName(r)
|
name, err := appName(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
fmt.Fprint(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
out, err := createJSIfNeeded(name)
|
out, err := createJSIfNeeded(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
t := template.JSEscapeString(template.HTMLEscapeString(err.Error()))
|
||||||
fmt.Fprint(w, err.Error())
|
js := `
|
||||||
|
window.onload = function() {
|
||||||
|
document.body.innerHTML="<pre style='white-space: pre-wrap;'><code>` + t + `</code></pre>";
|
||||||
|
}`
|
||||||
|
w.Header().Set("Content-Type", "text/javascript")
|
||||||
|
fmt.Fprintf(w, js)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := serveFile(w, out, "text/javascript"); err != nil {
|
if err := serveFile(w, out, "text/javascript"); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
fmt.Fprint(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,20 +124,17 @@ func serveMainJS(w http.ResponseWriter, r *http.Request) {
|
|||||||
func serveMainJSMap(w http.ResponseWriter, r *http.Request) {
|
func serveMainJSMap(w http.ResponseWriter, r *http.Request) {
|
||||||
name, err := appName(r)
|
name, err := appName(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
fmt.Fprint(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
out, err := createJSIfNeeded(name)
|
out, err := createJSIfNeeded(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
fmt.Fprint(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
out += ".map"
|
out += ".map"
|
||||||
if err := serveFile(w, out, "application/octet-stream"); err != nil {
|
if err := serveFile(w, out, "application/octet-stream"); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
fmt.Fprint(w, err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user