コード例 #1
0
ファイル: app.go プロジェクト: kirillrdy/nadeshiko
//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
ファイル: page.go プロジェクト: kirillrdy/nadeshiko
//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)
	}
}