Home

Awesome

This sample project illustrates a React/Redux application with optional server-side rendering bundled with Webpack.

Features

<img src="https://raw.githubusercontent.com/catamphetamine/webpack-react-redux-server-side-render-example/master/docs/images/screenshot.png" width="840" height="330"/>

Quick Start

Development

Note: The development script currently doesn't seem to work on my Windows machine. It stalls for a long time and then throws an error:

[Error: EBUSY: resource busy or locked, lstat 'c:\DumpStack.log.tmp'] {
  errno: -4082,
  code: 'EBUSY',
  syscall: 'lstat',
  path: 'c:\\DumpStack.log.tmp'
}
ERROR: "development:client:build" exited with 1.
ERROR: "development" exited with 1.

Production

<details> <summary>How to see non-minified React errors during <code>npm run production</code></summary>

Replace --mode production with --mode development in package.json in production:client:build script.

</details>

Summary

This application consists both of the "client side" and the "server side" (for illustration purposes).

The "client side" is the javascript code (./src/index.js) which is built by Webpack and run in a web browser, along with the "page rendering service" (./rendering-service) which does the same thing but in a Node.js process on the server providing "Server-Side Rendering" capability.

The "server side" consists of the "API" (./api) and the "proxy server" (./proxy-server).

The "proxy server" approach illustrated in this app is for illustration purposes only. It is considered old-fashioned now as all modern applications are becoming more distributed and decentralized running API in a cloud (e.g. Amazon Lambda) and serving "statics" from a whole another place (e.g. Amazon S3, configured via output.publicPath in webpack.config.js) in which case the React application queries the API server by an absolute URL (this is called "CORS") and no proxying is needed, therefore the whole "proxy server" is moved out of the equation.

In this example though, for simplicity, "proxy server" is used and it runs on port 3000 and routes all relative URL paths to their destinations:

In development mode there's one more Node.js process running: webpack serve is running on port 3000 which serves the "assets" compiled by Webpack (live) via HTTP protocol. In production there's no webpack serve and Webpack just outputs those compiled assets to the ./build folder and the "proxy server" serves those "assets" from there. In a real production environment though this "hand made" sample proxy server would have been dropped in favour of a proper proxy like NginX or HAProxy.