olebedev / go-starter-kit

[abandoned] Golang isomorphic react/hot reloadable/redux/css-modules/SSR starter kit
Other
2.82k stars 358 forks source link

Easy way to turn off server side JS rendering #24

Closed dimroc closed 8 years ago

dimroc commented 8 years ago

I'm running into JS issues when trying to render the JS on the golang server via duktape.

Is there a line of code I can comment out or a command line I can use to toggle off server side JS rendering? I've been mucking around in here:

https://github.com/olebedev/go-starter-kit/blob/1e850a27135f90e85981c0bcc18d4df032aa1337/src/app/server/react.go#L65

I'm ultimately trying to use redux with react-router with redux-simple-router, but it doesn't render server side.

I'm merely looking for something to unblock me at this point.

olebedev commented 8 years ago

Easy way to discard server side JS rendering is adding your own handler instead of app.React.Handle. For example, it could be added here as well.

It's pretty easy to write own:

func noJsRender(c *echo.Context) error {
  return c.Render(http.StatusOK, "react.html", resp{
    "uuid": c.Get("uuid").(*uuid.UUID).String(),
    "title":"my awesome app",
    "meta":"my meta tags to add at the head of the page",
  })
}

Then replace return app.React.Handle(c) to return noJsRender(c). That's it.

dimroc commented 8 years ago

Thanks Oleg

On Mon, Dec 14, 2015 at 11:08 PM Oleg Lebedev notifications@github.com wrote:

Easy way to discard server side JS rendering is adding your own handler instead of app.React.Handle. For example, it could be added here https://github.com/olebedev/go-starter-kit/blob/master/src/app/server/app.go#L122 as well.

It's pretty easy to write own:

func noJsRender(c _echo.Context) error { return c.Render(http.StatusOK, "react.html", resp{ "uuid": c.Get("uuid").(_uuid.UUID).String(), "title":"my awesome app", "meta":"my meta tags to add at the head of the page", }) }

Then replace return app.React.Handle(c) to return noJsRender(c). That's it.

— Reply to this email directly or view it on GitHub https://github.com/olebedev/go-starter-kit/issues/24#issuecomment-164639354 .