The purpose of this article is to demonstrate how you can serve your React.js Single Page Application (SPA) with a Go server and combine the entire application into a single binary file, able to run in any operating system.
For this tutorial you will need:
$ go get ``[github.com/GeertJohan/go.rice](https://github.com/GeertJohan/go.rice)
)$ npm i create-react-app
)$ npm i react-router-dom
)react-go-binary
, inside your GOPATH
where all of our code will liveAs a first step, we are going to generate our React.js frontend client using the wonderful CLI tool _create-react-app _developed by the React Engineer Team at Facebook.
All we have to do is to run $ npx create-react-app ./client
inside our project directory (e.x. react-go-binary) and a new directory client
will be created, including pretty standard source files.
The client will include a simple navigation bar and two (2) pages, a home and a ping page with a button to make a http request on our REST API.
We will put our logic on the src/App.js
file regarding router, pages and render our application from the src/index.js
file.
Define the App functional component which includes the router, the home component, the ping component and the navbar component on the src/App.js
file.
#reactjs #golang #go #cross-platform #react