Exemple #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	bundle, _ := ioutil.ReadFile("./build/bundle.js")
	http.Handle("/", selfjs.New(runtime.NumCPU(), string(bundle)))
	http.Handle("/favicon.ico", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(204)
	}))
	http.Handle("/universal.js", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "./build/bundle.js")
	}))

	http.ListenAndServe(":8080", nil)
}
Exemple #2
0
func TestHandler(t *testing.T) {
	w := httptest.NewRecorder()
	r, _ := http.NewRequest("GET", "/", nil)
	selfjs.New(1, script).ServeHTTP(w, r)
	eq(t, "Hello World!\n", w.Body.String())
}