• Stars
    star
    250
  • Rank 162,397 (Top 4 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample React/Redux/Webpack project with Server-Side Rendering

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

Features

  • React
  • Redux
  • Server-Side Rendering in production mode (optional feature)
  • Webpack 4
  • Development mode: hot reload for React components, hot reload for Redux reducers and actions
  • (optional) Code splitting

Quick Start

  • npm install

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.
  • npm run dev
  • wait for it to finish (it will say "Now go to http://127.0.0.1:3000" in the end)
  • go to http://localhost:3000
  • interact with the development version of the web application
  • Ctrl + C

Production

  • npm run production
  • wait for Webpack to finish the build (green stats will appear in the terminal, and it will print "Webpage rendering service is listening at port 3001" when the application has started)
  • go to http://localhost:3000
  • interact with the production version of the web application
  • check out ./build/bundle-stats.html and ./build/bundle-stats-2.html for detailed info on which modules take up the most space in the output bundle
How to see non-minified React errors during npm run production

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

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:

  • "statics" ("static files", "assets") are served (in production mode only) on /assets URL path
  • /api is proxied to the "API server" (running on port 3002)
  • all the other URLs are proxied to the "page rendering service" (which runs on port 3001).

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.

More Repositories

1

libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
JavaScript
2,520
star
2

webpack-isomorphic-tools

Server-side rendering for your Webpack-built applications (e.g. React)
JavaScript
1,260
star
3

react-phone-number-input

React component for international phone number input
JavaScript
882
star
4

universal-webpack

Isomorphic Webpack: both on client and server
JavaScript
687
star
5

javascript-time-ago

International highly customizable relative date/time formatting
JavaScript
362
star
6

read-excel-file

Read *.xlsx files in a browser or Node.js. Parse to JSON with a strict schema.
JavaScript
275
star
7

react-pages

A complete solution for building a React/Redux application: routing, page preloading, (optional) server-side rendering, asynchronous HTTP requests, document metadata, etc.
JavaScript
179
star
8

webapp

web application boilerplate (React, Redux, React-router, i18n, isomorphic, etc)
JavaScript
124
star
9

react-styling

Transforms CSS-alike text into a React style JSON object
JavaScript
122
star
10

virtual-scroller

A component for efficiently rendering large lists of variable height items
JavaScript
122
star
11

react-time-ago

Localized relative date/time formatting in React
JavaScript
96
star
12

react-responsive-ui

Responsive React UI components
JavaScript
69
star
13

relative-time-format

A convenient `Intl.RelativeTimeFormat` polyfill
JavaScript
62
star
14

require-hacker

Provides a hooking mechanism for Node.js require() calls
JavaScript
62
star
15

country-flag-icons

Vector (*.svg) country flag icons in 3x2 aspect ratio
HTML
62
star
16

anychan

A universal web client for online discussion services like "forums" or "imageboards".
JavaScript
50
star
17

input-format

Formatting user's text input on-the-fly
JavaScript
27
star
18

jquery-full-house

(obsolete, deprecated) fills an html block with predefined text, so that font size automatically adjusts itself to the maximum
HTML
15
star
19

es6-tree-shaking-test

Tests whether your ES6-aware module bundler actually performs "tree shaking" (unused code elimination)
JavaScript
14
star
20

imageboard

An easy uniform wrapper over the popular imageboards' API
JavaScript
13
star
21

easy-react-form

Simple, fast and easy-to-use React Form.
JavaScript
13
star
22

write-excel-file

Write simple *.xlsx files in a browser or Node.js
JavaScript
12
star
23

react-website-basic-example

`react-website` basic example
JavaScript
12
star
24

wheely-ios-test

A test for iOS developer position at Wheely
Objective-C
9
star
25

web-service

Instantiates web services: REST Api, file upload, etc
JavaScript
6
star
26

sociopathy

an unusual social network
JavaScript
5
star
27

serverless-functions

Serverless functions toolkit (e.g. AWS Lambda)
JavaScript
2
star
28

social-components-parser

Parses post content
JavaScript
2
star
29

on-scroll-to

A DOM Element that triggers an action whenever it's scrolled into viewport
JavaScript
2
star
30

react-website-webpack-example

An example of using `react-website` with Webpack
JavaScript
1
star
31

chartogram

Charts in JS with no dependencies
JavaScript
1
star
32

simple-http-file-server

A simple HTTP static file server
JavaScript
1
star
33

webapp-db

JavaScript
1
star
34

webapp-backend

JavaScript
1
star
35

print-error

Javascript print error stack trace (pretty, terminal, html, markdown, etc)
JavaScript
1
star
36

deviantart_photo_stream

DeviantArt powered digital signage for your second display
JavaScript
1
star
37

react-sortable-dnd-list

A sortable Drag&Drop list React component
JavaScript
1
star
38

react-pages-basic-example

`react-pages` basic example
JavaScript
1
star
39

halt-hammerzeit.github.io

HTML
1
star