Skip to content

Golang isomorphic react/hot reloadable/redux/css-modules starter kit

License

Notifications You must be signed in to change notification settings

augustoroman/go-react-v8-ssr

 
 

Repository files navigation

go-react-v8-ssr: Work-in-progress

Go server serving a react-based website using server-side rendering powered by V8.


This repo is forked from the awesome go-starter-kit.

I forked that project and am modifying to get a better understanding of how it works. And use some of the tools I'm more familiar with. There are many changes, but some of the major ones include:

  • rework the JS rendering engine to use either v8 or duktape On windows, only duktape is allowed and used by default.
  • simplify the server code to be an easier-to-understand example
  • use modd instead of on for running the server.
  • use go-rice instead of go-bindata for embedding the data.
  • use govendor rather than srlt

Installation

Make sure you have:

  • golang
  • node.js with npm, only to build the application bundle at compile time. For windows, it's very important that you have a recent npm, otherwise the npm install will fail because the directory paths are too long.
  • GNU make

Clone the repo

$ git clone [email protected]:augustoroman/go-react-v8-ssr.git $GOPATH/src/github.com/<username>/<project>
$ cd $GOPATH/src/github.com/<username>/<project>

Install some go-based utilities:

$ go get -u github.com/kardianos/govendor
$ go get -u github.com/GeertJohan/go.rice/rice
$ go get -u github.com/cortesi/modd

Install dependencies:

$ govendor sync
$ npm install

Build V8

See instructions at https://github.com/augustoroman/v8

Add v8 symlinks

$ vendor/github.com/augustoroman/v8/symlink.sh <V8-DIR>

Run development

Start dev server:

$ modd

that's it. Open http://localhost:5001/(if you use default port) at your browser. Now you ready to start coding your awesome project.

Build

Install dependencies and type NODE_ENV=production make build. This rule produces the production webpack build and that is embedded into the go server, then builds the server. You can find the result at ./bin/server.


Project structure

The server's entry point
$ tree server
server
├── main.go <-- main function declared here
├── react-v8.go
├── bindata.go <-- this file is gitignored, it will appear at compile time
└── data
    ├── static
    |   └── build <-- this dir is populated by webpack automatically
    └── templates
        └── react.html

The ./server/ is flat golang package.

The client's entry point

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.

License

MIT

About

Golang isomorphic react/hot reloadable/redux/css-modules starter kit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 51.7%
  • JavaScript 37.5%
  • CSS 4.5%
  • HTML 4.0%
  • Makefile 2.3%