Beispiel #1
0
//Handler returns handler that will serve a given gopherjs app
func (app App) Handler() http.HandlerFunc {

	return func(response http.ResponseWriter, request *http.Request) {

		//TODO this is clearly for dev only
		if request.URL.Path != "/" {
			log.Println(request.URL.Path)
			goPath := os.Getenv("GOPATH")
			http.ServeFile(response, request, goPath+"/src"+request.URL.Path)
			return
		}

		//TODO dont do this here
		err := app.compile(response)
		if err != nil {
			//http.Error(response, err.Error(), http.StatusInternalServerError)
			return
		}

		page := html.Html().Children(
			html.Head().Children(
				html.Script().Src(app.CompiledJsFileWebPath()),
			),
			html.Body(),
		)
		page.WriteTo(response)
	}
}
Beispiel #2
0
//Handler returns handler that will serve a given gopherjs app
func (app App) Handler() http.HandlerFunc {

	return func(response http.ResponseWriter, request *http.Request) {
		//TODO dont do this here
		err := app.compile()
		if err != nil {
			http.Error(response, err.Error(), http.StatusInternalServerError)
			return
		}

		page := html.Html().Children(
			html.Head().Children(
				html.Script().Src(app.CompiledJsFileWebPath()),
			),
			html.Body(),
		)
		page.WriteTo(response)
	}
}
Beispiel #3
0
//Scripts returns html.Nodes that are need to be placed on the page for nadeshiko to work
//TODO move somewhere else
// path argument is for where websocket handler will try to connect
func Scripts(path string) []html.Node {
	return []html.Node{
		html.Script().Attribute("src", jquery.WebPath),
		html.Script().TextUnsafe(SocketJSCode(path)),
	}
}