You’re right! The only thing the Go code does in this case is handle API calls, not serving up the UI at all. In fact, the node server that runs the UI is for development only. When you want to run this in production you’ll build the UI into a
dist folder and simply serve that statically to your clients. This does not mean they’d have to be hosted separately though (technically). While I would prefer using Netlify, Github Pages, or S3 to host the UI, you can have the Go api server up the static files in the
dist folder just fine.
Now I’m not entirely sure if you’re talking about deploying statically for a CSR app like this example or you’re talking about using go to server sider render your app. Although in both cases, the routing logic for the app itself are handled by React.
Assuming you’re talking about using Go to server side render a React app, here are my thoughts:
- Webpack support
It’s possible but I am hesitant to say there are good, well maintained libraries to help you bring webpack usage into Go. The fact is you’re going to probably have to do a lot of custom work to make it work with newer versions of React/Webpack
Go’s performance is great, but in all honesty, for this task, you’re really not going to notice a difference. This is not really worth the trying to juggle to languages together. However, delegating Go to only handle API calls is nice because of its type system, ability to build to a single binary, and of course you do get an edge in performance (but again, not really that big of a deal). Currently I’m working on a project that has both a Go lambda and Node.js lambda. The Go lambda deploys in seconds because only a binary gets uploaded while the Node one takes minutes (thanks node modules). So there’s also this angle to look at as well.
IMO it’s not worth it to try and SSR with Go. SSR configurations are hard with Node already, trying to use another language makes it even harder. This is especially the case when amazing tools such as Razzle exist to ease the pain for SSR apps. While Go has lots of use cases/benefits, I’d strongly recommend against trying to SSR with Go.