Giter Club home page Giter Club logo

go-react-v8-ssr's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.