示例#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)
	}
}
示例#2
0
//This is the default blank html page. that contains required clientside js code to have nadeshiko working
func Page(path string) io.WriterTo {
	return html.Html().Children(
		html.Head().Children(
			Scripts(path)...,
		),
		html.Body(),
	)
}
示例#3
0
文件: app.go 项目: kirillrdy/gopherjs
//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)
	}
}