This project contains a quick starter kit for Facebook React Single Page Apps with Golang server side render and also with a set of useful features for rapid development of efficient applications.
- server side render via go-duktape
- api requests between your react application and server side application directly via fetch polyfill for go-duktape at server side, and it is possible to process requests with user session as well
- title, Open Graph and other domain-specific meta tags render for each page at the server and at the client
- server side redirect
- embedding static files into artefact via bindata
- high performance echo framework
- advanced cli via cli
- Makefile based project
- one(!) terminal window process for development
- routing via react-router
- ES6 & JSX via babel-loader with minimal runtime dependency footprint
- redux as state container
- redux-devtools
- stylus css styles without global namespace via css-loader & css-modules
- separate css file to avoid FOUC
- hot reloading via react-transform & HMR
- webpack bundle builder
- eslint and golint rules for Makefile
- golang
- node.js with npm, only to build the application bundle at compile time
- GNU make
- fswatch
- go-bindata
- srlt - optional
Note that probably not works at windows.
$ tree server
server
├── api.go
├── app.go
├── bindata.go <-- this file is gitignored, it will appear at compile time
├── conf.go
├── data
│ └── templates
│ └── react.html
├── main.go <-- main function declared here
├── react.go
└── utils.go
The ./server/
is flat golang package.
It's simple React application
$ tree client
client
├── actions.js
├── components
│ ├── app
│ │ ├── favicon.ico
│ │ ├── index.js
│ │ └── styles.css
│ ├── homepage
│ │ ├── index.js
│ │ └── styles.css
│ ├── not-found
│ │ ├── index.js
│ │ └── styles.css
│ └── usage
│ ├── index.js
│ └── styles.css
├── css
│ ├── funcs.js
│ ├── global.css
│ ├── index.js
│ └── vars.js
├── index.js <-- main function declared here
├── reducers.js
├── router
│ ├── index.js
│ ├── routes.js
│ └── toString.js
└── store.js
The client app will be compiled into server/data/static/build/
. Then it will be embedded into go package via go-bindata. After that the package will be compiled into binary.
Convention: javascript app should declare main function right in the global namespace. It will used to render the app at the server side.
Clone the repo:
$ git clone git@github.com:olebedev/go-starter-kit.git $GOPATH/src/github.com/<username>/<project>
$ cd $GOPATH/src/github.com/<username>/<project>
Install JavaScript dependencies:
$ npm i
There are two ways to install Golang dependencies:
- Traditional
go get
. It is not recommended because it will install packages into$GOPATH
and the packages versions are will not be under control. This is OK for Golang < 1.5.
$ go get ./server/.
- Via revision locking tool - srlt. Make sure that you have srlt installed, environment variable
GO15VENDOREXPERIMENT=1
and Golang >= 1.5.0.
$ srlt restore
This command will install dependencies into ./vendor/
folder located in root.
Then install go-bindata
directly: go install github.com/jteeuwen/go-bindata
Start dev server:
$ make serve
that's it. Open http://localhost:5001/(if you use default port) at your browser. Now you ready to start coding your awesome project.
Install dependencies and type NODE_ENV=production make build
. This rule is producing webpack build and regular golang build after that. Result you can find at $GOPATH/bin
. Note that the binary will be named as the current project directory.
MIT