Giter VIP home page Giter VIP logo

universal-redux-template's Introduction

Build Status

Universal Redux Template

A boilerplate doing universal/isomorphic rendering with Redux + React-router + Express, based on Redux-Realword-Example

Philosophy

To bootstrap a React app development environment is not an easy task, there are so many libraries to setup, including webpack, babel, testing stuff and others. I'd like this boilerplate to be a ready-to-use one with the essential tools and the simplest logic that just work to build a universal rendering React + Redux app. That's why there is no fancy stuff in this app, since it's a basis of your killer app rather than a showcase one.

How to use this template?

  • clone this app and name it as whatever your want: $ git clone https://github.com/mz026/universal-redux-template.git my-killer-app

  • remove the .git folder since you won't need the history of this boilerplate: $ cd my-killer-app; rm -rf .git

  • start out a new git history: $ git init

  • Install dependencies: $ yarn install

  • Host dev environment and start to build something changing the world! $ yarn start

  • To run the test with Mocha, Enzyme, Sinon and Chai: $ yarn test:ci

  • To generate a container/component/action and its tests: $ ./bin/generate <type> <path>

eg: $ ./bin/generate component myNamespace/MyComponent

Features:

  • Universal rendering, with async data support
  • Server side redirect
  • Separate vendor and app js files
  • Use Immutable as store data
  • Hot Reload on client side by Webpack
  • Hot Reload on server side (ref)

Stack:

Testing:

Tools:

Development process:

When developing a feature,

  • First run a separate process converting ES6 to ES5 lively:
$ yarn run test:watch
  • Run the test case of a single file/directory by:
$ yarn test -- <the-file-path>

For example:

$ yarn test -- app/test/actions
  • Before deployment, run all the test cases to make sure everything is fine by:
$ yarn test:ci

Why

The way suggested by babel's doc compiles the code on the fly, which is too slow, especially when the number of files grows:

//package.json

{
  "scripts": {
    "test": "mocha --compilers js:babel-register"
  }
}

So here we pre-compile the code, watch it, and maintain a cache to avoid repeated build of the files that doesn't change. After the pre-compile, the testing cycle can be much faster than before, especially when doing TDD.

For Winners Vimmers:

For vim users, there's a plugin called vim-test binding tests with the editor. You can trigger a test "nearest the cursor", which is super handy when doing TDD.

To make vim-test work together with the pre-compile process,

  1. copy the editor_configs/vimrc to <project-root>/.vimrc
  2. make sure these two lines exist in your ~/.vimrc to enable directory-based .vimrc:
set exrc
set secure

Then you can enjoy the fast feedback loop powered by the greatest editor on the planet.

Routes Draft:

  • Intro page: {base_url}
  • Questions Page: {base_url}/questions
  • Question Detail Page: {base_url}/questions/:id

How it works:

Assets Management

When handling static assets, we want to achieve the following goals:

  • Make assigning assets url a no-brainer
  • Apply revision when deploying to production to integrate with CDN services easily

The usage example can be found in [Intro Container](https://github.com/mz026/universal-redux-template/blob/master/app/containers/Intro.js)

We achieve this by:

First, creating an assets container folder: app/assets

In development mode:

Assign static folder linking /assets to the folder above

In production mode:

Use a gulp task (gulp build) to handle it:

  • A set of [rev](https://github.com/smysnk/gulp-rev-all)-ed assets with hash code appended would be built into dist/public/assets
  • A static middleware mapping root url to the folder mentioned above is configured in server.js
  • A set of [revReplace](https://github.com/jamesknelson/gulp-rev-replace)-ed server code would be built into dist/server-build, so that the rev-ed assets can be used when doing server rendering

Redirect after API Calls

Under some cases, we'd like to do 302 redirect after fetching API. For example:

When users try to access a question page via an unexisting Id, redirect her to Index route.

In the code layer, we want the implementation to be shared on both client and server side. This is achieved by passing a history instance to action creators, and use history.push whenever needed.

On the client side, react-router would then take care the rest of redirecting logic, while on server side, we subscribe the url-chaning events on each request, and redirect requests to proper pages if needed.

Such implementation can be found in QuestionContainer, questions action

Vendor Scripts:

Vendor related scripts are bundled into a vendor.js, associated settings can be found in the entry field of webpack.config.js.

(thanks @dlombardi for pointing it out!)

For Windows Users:

yarn test:

The single quotes in yarn test script surrounding path do not work on Windows, while they're necessary on unix-like machines. Please remove them in scripts.test section in package.json like this:

"test": "NODE_ENV=test NODE_PATH=./app mocha --compilers js:babel-register -r app/spec/support/setup.mocha.js --recursive app/spec/**/*.test.js -w"

(thanks @jbuffin for pointing it out!)

Deployment:

To deploy this app to production environment:

  • Prepare a server with NodeJS environment

  • Use whatever tool to upload this app to server. (Capistrano is a good choice.)

  • Run $ NODE_ENV=production yarn install on server

    • After the installation above, postinstall script will run automatically, building front-end related assets and rev-ed server code under dist/ folder.
  • Kick off the server with:

NODE_ENV=production NODE_PATH=./dist/server-build node dist/server-build/server

Deploy to Heroku

To deploy this app to heroku,

  • Set up heroku git remote url
  • Set API_BASE_URL to heroku config var. (without trailing slash)

Here's a sample deployed to heroku: https://redux-template-test.herokuapp.com/ For this case, the API_BASE_URL mention above would be https://redux-template-test.herokuapp.com

Resources:

universal-redux-template's People

Contributors

bolicd avatar cesine avatar fetzig avatar jbuffin avatar joewestcott avatar marccoll avatar mz026 avatar sabervision avatar tylershin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

universal-redux-template's Issues

how to use with redux-form?

I've been trying to integrate this reduxForm, are there any suggestions on how to use?

first, for anyone else trying to use, their docs say to use this, but this code doesn't work with this repo

export default reduxForm({
  form: 'simple'  // a unique identifier for this form
})(SimpleForm)

where reduxForm takes the place of connect from react-redux. you get an error saying 'cannot find fetchData of undefined' because in server.js, getReduxPromise looks for a WrappedComponent in renderProps.component, which comes from the connect function, and sets it to a variable called comp. reduxForm there is no WrappedComponent in renderProps.component, so comp.fetchData shows that error since comp doesn't exist.

I then tried this

const SimpleForm2 = reduxForm({
  form: 'simple'  // a unique identifier for this form
})(SimpleForm)


export default connect(null, null)(SimpleForm2)

which does render the page and bypass the 'cannot find fetchData of undefined' errors, the form shows, but nothing inside the forms render

anyone ever used redux form with this successfully?

CALL_API question

Hello,

first of all, great boilerplate, I like it a lot, so far I havent had problems with it.

I do have a question regarding CALL_API tho: How do you handle "failure" type. I can see there is successType, which will be executed if call is success but is there any failureType which will be executed if api call fails?

Thank you

npm install ERR

I'm getting this error when running npm install on this project.

npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/slash/.nvm/versions/node/v4.3.1/bin/node" "/Users/slash/.nvm/versions/node/v4.3.1/bin/npm" "install"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.3
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.1
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.7
npm ERR! peerinvalid Peer [email protected] wants react@>=0.13.2 || ^0.14.0-rc1

Trying to populate redux store in onEnter hook of react router.

I want to call static fetchData of component in onEnter hook so that i can populate the store with data.
i just don't know how can i do this. or any other way i can load the data before component render will be helpful..
I am trying to do this as following..

Here is my route.
<Route path='/edit/profile' component={requireAuth(EditProfile)} onEnter={loadData}/>
here is my loadData function
function loadData(nextState, replace,callback) { if (nextState && nextState.routes.length > 0) { console.log(nextState) callback() } }

updated dependency versions?

i know it's been a while since this came out, but a lot of the versions are out of data by now. i'll tinker around with versioning and maybe submit a PR but wanted to throw it out there

Instructions on installing vendor packages

It'd be nice if the readme included steps to install vendor packages. I'm not sure where the vendor.js in the dist is sourcing from or how to include packages in there.

Error: Couldn't find preset "stage-1" relative to directory

i ran NODE_ENV=production npm install command and installed node modules then i ran NODE_ENV=production NODE_PATH=./app node app/server command.. But it's giving me Error: Couldn't find preset "stage-1" relative to directory. Any ideas?

My .babelrc is like following.
{
"presets": ["es2015", "react","stage-1"],
"env": {
"test": {
"plugins": [ "babel-plugin-rewire" ]
}
}
}

Warning: React attempted to reuse markup in a container but the checksum was invalid.

Hi,

not sure whats happening, if im doing something wrong here but 2 things i've noticed when trying to use this boilerplate on Windows 10 machine:

  1. Clone this repo, yarn install, yarn start - works.However, any change to any component results in : Warning: React attempted to reuse markup in a container but the checksum was invalid. For example trying to change Intro.js title.

  2. Build script for components are not working it seems. Getting Error: Command failed: mkdir -p errors

Am I missing something here?

Thanks

[QUESTION] Deployment API_BASE_URL

Hi,

is there a way to add wildcard or something else to API_BASE_URL param?

Im asking this because I have a domain www.something.com. If i set API_BASE_URL , everything works but if I do something.com, I get CORS error.

Since I can set only one API_BASE_PARAM any way to set it to work in both ways? (www and * )

THanks

Gulp Rev Not Working?

I seem to be having a problem deploying to production. My gulp rev task runs and generates the manifest.json file but doesn't rename the files in assets/ when it places them in server-build. Any idea what I might be overlooking? Currently using NPM to run the deploy process on Mac, same issue on linux

2017-03-23T18:13:41.743515+00:00 app[web.1]: Error: Cannot find module 'assets/javascripts/material.min.115d3a6a.js'

assets/javascripts/material.min.js exists, no rev'd version

POST Requests Not Firing?

I'm a huge fan of this boilerplate but I seem to be having some issues getting POST requests to work. I took a look at some previous issues around POST requests and I seem to be using the middleware properly but I don't see any network activity and nothing is happening (the GETs I've implemented have worked really well!).

Here's the code:

server.post('/api/post', (req, res) => {
console.log('server post');
res.status(200).send({status: 'ok'});
})

export const TEST_POST = Symbol('TEST_POST');
export const TEST_POST_ERROR = Symbol('TEST_POST_ERROR');
export function testPost () {
console.log('Test post action');
return {
[CALL_API]: {
method: 'post',
path: '/api/post',
afterSuccess: () => {console.log('test post succes');},
successType: TEST_POST,
errorType: TEST_POST_ERROR
}
}
}

case ActionType.TEST_POST:
console.log('Test post success');
return state;
case ActionType.TEST_POST_ERROR:
console.log('Test post eror');
return state;

Any and all suggestions would be very appreciated!

use css-loader in webpackage,but not work?

我想在 react components 內 載入 css 製作 ui, 於是我使用了 css-loader 於 webpackage,
但我依據webpackage2.2 官方建議的的使用方法都無法順利加載 css,不知道是什麼問題?

SyntaxError: /Users/Allen/Documents/react/universal-redux-template-master/app/components/Nav/NavC1.css: Unexpected token (1:0)
[0] > 1 | .header {
[0] | ^
[0] 2 | color: #00ccff;
[0] 3 | }
[0] at Parser.pp$5.raise (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:4246:13)
[0] at Parser.pp.unexpected (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:1627:8)
[0] at Parser.pp$3.parseExprAtom (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3586:12)
[0] at Parser.parseExprAtom (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:6402:22)
[0] at Parser.pp$3.parseExprSubscripts (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3331:19)
[0] at Parser.pp$3.parseMaybeUnary (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3311:19)
[0] at Parser.pp$3.parseExprOps (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3241:19)
[0] at Parser.pp$3.parseMaybeConditional (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3218:19)
[0] at Parser.pp$3.parseMaybeAssign (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3181:19)
[0] at Parser.parseMaybeAssign (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:5694:20)
[0] at Parser.pp$3.parseExpression (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:3143:19)
[0] at Parser.pp$1.parseStatement (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:1774:19)
[0] at Parser.parseStatement (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:5218:22)
[0] at Parser.pp$1.parseBlockBody (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:2133:21)
[0] at Parser.pp$1.parseTopLevel (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:1645:8)
[0] at Parser.parse (/Users/Allen/Documents/react/universal-redux-template-master/node_modules/babylon/lib/index.js:1537:17)
[0] [nodemon] app crashed - waiting for file changes before starting...

checksum was invalid

I want to perform this check if the current route is '/' and change some styling... so i tried doing:

<div style={(global.location && global.location.pathname ===  '/' ) ? style1 : style2}></div>

But it gives me checksum warning. something like...
React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) 0,0,0,0);box-shadow:none;border-radius:0
(server) 0,0,0,0);box-shadow:0 1px 6px rgba(0, 0,

how am i suppose to solve this?

Posting form data to the backend using the api setup

How would you go about Implementing a post request using this repo. api setup?
I've been examining the api.js and server.js files, and I'm not completely sure how should I send the form's data to the server using the promise system you've setup.

npm start fails with "concurrent" command is deprecated, use "concurrently" instead.

Any ideas how to workaround this ?
Only way I manage to get the server up was with $ NODE_PATH=./app node app/server

$ npm start
> universal-redux-template@0.0.0 start /opt/test-react
> cross-env NODE_PATH=./app concurrent --kill-others "nodemon app/server" "node webpack.server.js"

"concurrent" command is deprecated, use "concurrently" instead.

[0] (node) v8::ObjectTemplate::Set() with non-primitive values is deprecated
[0] (node) and will stop working in the next major release.
[0] 
[0] ==== JS stack trace =========================================
[0] 
[0] Security context: 0x20fd5b5c9fa9 <JS Object>#0#
[0]     1: .node [module.js:568] [pc=0x1dbb0fece124] (this=0x336958bcb331 <an Object with map 0x1c12ade17be1>#1#,module=0x1051fee79 <a Module with map 0x1c12ade181b9>#2#,filename=0x1051fee51 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>)
[0]     2: load [module.js:456] [pc=0x1dbb0fe39ad2] (this=0x1051fee79 <a Module with map 0x1c12ade181b9>#2#,filename=0x1051fee51 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>)
[0]     3: tryModuleLoad(aka tryModuleLoad) [module.js:415] [pc=0x1dbb0fe395fd] (this=0x20fd5b504189 <undefined>,module=0x1051fee79 <a Module with map 0x1c12ade181b9>#2#,filename=0x1051fee51 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>)
[0]     4: _load [module.js:407] [pc=0x1dbb0fe35242] (this=0x336958bcb2e9 <JS Function Module (SharedFunctionInfo 0x336958b286b9)>#3#,request=0x1051f8329 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>,parent=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,isMain=0x20fd5b504299 <false>)
[0]     5: require [module.js:~463] [pc=0x1dbb0fe8f9eb] (this=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,path=0x1051f8329 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>)
[0]     6: require(aka require) [internal/module.js:20] [pc=0x1dbb0fe43346] (this=0x20fd5b504189 <undefined>,path=0x1051f8329 <String[94]: /opt/test-react/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node>)
[0]     7: /* anonymous */ [/opt/test-react/node_modules/fsevents/fsevents.js:11] [pc=0x1dbb0fe86c12] (this=0x105004b81 <an Object with map 0x199ce7007bc9>#5#,exports=0x105004b81 <an Object with map 0x199ce7007bc9>#5#,require=0x105004969 <JS Function require (SharedFunctionInfo 0x336958b591e1)>#6#,module=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,__filename=0x105004b29 <String[57]: /opt/test-react/node_modules/fsevents/fsevents.js>,__dirname=0x105004b01 <String[45]: /opt/test-react/node_modules/fsevents>)
[0]     8: _compile [module.js:541] [pc=0x1dbb0fe425a4] (this=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,content=0x105006519 <Very long string[3154]>#7#,filename=0x105004b29 <String[57]: /opt/test-react/node_modules/fsevents/fsevents.js>)
[0]     9: .js [module.js:550] [pc=0x1dbb0fe3b0cb] (this=0x336958bcb331 <an Object with map 0x1c12ade17be1>#1#,module=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,filename=0x105004b29 <String[57]: /opt/test-react/node_modules/fsevents/fsevents.js>)
[0]    10: load [module.js:456] [pc=0x1dbb0fe39ad2] (this=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,filename=0x105004b29 <String[57]: /opt/test-react/node_modules/fsevents/fsevents.js>)
[0]    11: tryModuleLoad(aka tryModuleLoad) [module.js:415] [pc=0x1dbb0fe395fd] (this=0x20fd5b504189 <undefined>,module=0x1050048d9 <a Module with map 0x1c12ade181b9>#4#,filename=0x105004b29 <String[57]: /opt/test-react/node_modules/fsevents/fsevents.js>)
[0]    12: _load [module.js:407] [pc=0x1dbb0fe35242] (this=0x336958bcb2e9 <JS Function Module (SharedFunctionInfo 0x336958b286b9)>#3#,request=0x336958bb1701 <String[8]: fsevents>,parent=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,isMain=0x20fd5b504299 <false>)
[0]    13: require [module.js:~463] [pc=0x1dbb0fe43613] (this=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,path=0x336958bb1701 <String[8]: fsevents>)
[0]    14: require(aka require) [internal/module.js:20] [pc=0x1dbb0fe43346] (this=0x20fd5b504189 <undefined>,path=0x336958bb1701 <String[8]: fsevents>)
[0]    15: /* anonymous */ [/opt/test-react/node_modules/chokidar/lib/fsevents-handler.js:7] [pc=0x1dbb0fe8654a] (this=0x1050080a1 <an Object with map 0x199ce7007bc9>#9#,exports=0x1050080a1 <an Object with map 0x199ce7007bc9>#9#,require=0x105007e89 <JS Function require (SharedFunctionInfo 0x336958b591e1)>#10#,module=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,__filename=0x105008041 <String[69]: /opt/test-react/node_modules/chokidar/lib/fsevents-handler.js>,__dirname=0x105008019 <String[49]: /opt/test-react/node_modules/chokidar/lib>)
[0]    16: _compile [module.js:541] [pc=0x1dbb0fe425a4] (this=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,content=0x10500b079 <Very long string[12063]>#11#,filename=0x105008041 <String[69]: /opt/test-react/node_modules/chokidar/lib/fsevents-handler.js>)
[0]    17: .js [module.js:550] [pc=0x1dbb0fe3b0cb] (this=0x336958bcb331 <an Object with map 0x1c12ade17be1>#1#,module=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,filename=0x105008041 <String[69]: /opt/test-react/node_modules/chokidar/lib/fsevents-handler.js>)
[0]    18: load [module.js:456] [pc=0x1dbb0fe39ad2] (this=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,filename=0x105008041 <String[69]: /opt/test-react/node_modules/chokidar/lib/fsevents-handler.js>)
[0]    19: tryModuleLoad(aka tryModuleLoad) [module.js:415] [pc=0x1dbb0fe395fd] (this=0x20fd5b504189 <undefined>,module=0x105007df9 <a Module with map 0x1c12ade181b9>#8#,filename=0x105008041 <String[69]: /opt/test-react/node_modules/chokidar/lib/fsevents-handler.js>)
[0]    20: _load [module.js:407] [pc=0x1dbb0fe35242] (this=0x336958bcb2e9 <JS Function Module (SharedFunctionInfo 0x336958b286b9)>#3#,request=0x336958bb1dd9 <String[22]: ./lib/fsevents-handler>,parent=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,isMain=0x20fd5b504299 <false>)
[0]    21: require [module.js:~463] [pc=0x1dbb0fe43613] (this=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,path=0x336958bb1dd9 <String[22]: ./lib/fsevents-handler>)
[0]    22: require(aka require) [internal/module.js:20] [pc=0x1dbb0fe43346] (this=0x20fd5b504189 <undefined>,path=0x336958bb1dd9 <String[22]: ./lib/fsevents-handler>)
[0]    23: /* anonymous */ [/opt/test-react/node_modules/chokidar/index.js:13] [pc=0x1dbb0fe6b3f2] (this=0x179641cd4001 <an Object with map 0x199ce7007bc9>#13#,exports=0x179641cd4001 <an Object with map 0x199ce7007bc9>#13#,require=0x179641cd3e09 <JS Function require (SharedFunctionInfo 0x336958b591e1)>#14#,module=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,__filename=0x179641cd3fb1 <String[54]: /opt/test-react/node_modules/chokidar/index.js>,__dirname=0x179641cd3f89 <String[45]: /opt/test-react/node_modules/chokidar>)
[0]    24: _compile [module.js:541] [pc=0x1dbb0fe425a4] (this=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,content=0x179641cdeb89 <Very long string[21834]>#15#,filename=0x179641cd3fb1 <String[54]: /opt/test-react/node_modules/chokidar/index.js>)
[0]    25: .js [module.js:550] [pc=0x1dbb0fe3b0cb] (this=0x336958bcb331 <an Object with map 0x1c12ade17be1>#1#,module=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,filename=0x179641cd3fb1 <String[54]: /opt/test-react/node_modules/chokidar/index.js>)
[0]    26: load [module.js:456] [pc=0x1dbb0fe39ad2] (this=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,filename=0x179641cd3fb1 <String[54]: /opt/test-react/node_modules/chokidar/index.js>)
[0]    27: tryModuleLoad(aka tryModuleLoad) [module.js:415] [pc=0x1dbb0fe395fd] (this=0x20fd5b504189 <undefined>,module=0x179641cd3d79 <a Module with map 0x1c12ade181b9>#12#,filename=0x179641cd3fb1 <String[54]: /opt/test-react/node_modules/chokidar/index.js>)
[0]    28: _load [module.js:407] [pc=0x1dbb0fe35242] (this=0x336958bcb2e9 <JS Function Module (SharedFunctionInfo 0x336958b286b9)>#3#,request=0x336958ba73d1 <String[8]: chokidar>,parent=0x179641ce9659 <a Module with map 0x1c12ade181b9>#16#,isMain=0x20fd5b504299 <false>)
[0]    29: require [module.js:~463] [pc=0x1dbb0fe43613] (this=0x179641ce9659 <a Module with map 0x1c12ade181b9>#16#,path=0x336958ba73d1 <String[8]: chokidar>)
[0]    30: require(aka require) [internal/module.js:20] [pc=0x1dbb0fe43346] (this=0x20fd5b504189 <undefined>,path=0x336958ba73d1 <String[8]: chokidar>)
[1] Webpack dev server is listening at localhost:3001
[0] nodemon app/server exited with code null
--> Sending SIGTERM to other processes..
[1] node webpack.server.js exited with code null

npm ERR! Darwin 12.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.0.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! universal-redux-template@0.0.0 start: `cross-env NODE_PATH=./app concurrent --kill-others "nodemon app/server" "node webpack.server.js"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the universal-redux-template@0.0.0 start script 'cross-env NODE_PATH=./app concurrent --kill-others "nodemon app/server" "node webpack.server.js"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the universal-redux-template package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_PATH=./app concurrent --kill-others "nodemon app/server" "node webpack.server.js"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs universal-redux-template
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls universal-redux-template
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /opt/test-react/npm-debug.log

Unable to compile the complete app

Yesterday i started using your boilerplate and it works fine when running using

npm start

But i complied it using the command:

NODE_ENV=production npm run build

It creates a dist folder with everything except the node server file and the index.html file. So i am not able to create a dist folder so that i can deploy.
How do i resolve this issue?

Not an issue - Page refresh scenario

Many Thanks for putting it together. Please clarify , when the user refresh the page from this route http://localhost:3000/questions. Technically a request will be made to the server and express will call the /questionsapi internally and send the rendered HTML along with data and routing. But I see a request from the client to /questions api. Unsure why there is a data fetching call from the client when the user refresh the page.

Production reload

How do I make production not reload when changing routes? I mean refreshing pages. When this template runs on webpack-dev-server there is this live reload that I cannot replicate on production. It kind of looses the point of react when website refreshes on every click.

Auth system?

I managed to make simple communication with API. (thanks to your API middleware by the way which is really cool) But I am struggling to share "session information" between client and server. Could you please help me a little to figure out how do I read / write cookies so that both client and server can see them?

The problem is when user refreshes page with F5 or something. Then he looses all of his information.

I know that server has access to cookie via req.cookies but ... I don't understand where should I put logic concerning initial state for users that are already logged in.

I already spent hours trying to figure out how to do this slowly regreting making isomorphic application. I should have just stayed with client since I am totally new to react.

Can't load css/less in server render

I got problem when try my SSR code, everything is ok but when I import 'style.less' to component, it got error

Here my pagekage.json scripts
"prod": "NODE_ENV=production node server.js"

And in server.js, I add some loader but It dont work

require('babel-core/register')({
    presets: ['react', 'es2015', 'stage-2']
})
require('style-loader!css-loader!less-loader')

And I think, how to Ignore css/less in component on server rendering?

Server rendering requests data twice

It seems unnecessary to redo API call when page was rendered on the server. Maybe app/containers/Question.js should check for that like this?

  componentDidMount() {
    let { id } = this.props.params
    let { question } = this.props
    let loadedId = question.get('id')

    //if component was server-rendered, no need to reload
    if (loadedId !== id) {
      this.props.loadQuestionDetail({ id })
    }
  }

Or, maybe there is a better (less specific) way to do this?

PS: Thanks for the cool boilerplate!

How to use with redux thunk?

Apologies for coming here again! I realize I ask a lot of things :(

i just had a quick question about using redux thunk - the middleware api is throwing me off as to how i'm supposed to be making calls and the blog post, although helpful, didn't clear things up with this. I'm basically trying to do a call like this, however the returned dispatch functions never get called. Is there an ideal way to do this or use the middleware in using redux thunk?

export function fetchStuff() {
  return function(dispatch, getState) {
    dispatch({
      type: action_types.FETCH_STUFF_PENDING
    });
    
    return database.ref('my_node').once('value').then(function(snapshot) {
      let items = cleanResponse(snapshot.val(), getState());
      let k = '';

      // Add the items to the state.
      dispatch({
        type: action_types.FETCH_STUFF_FULFILLED,
        payload: {
          items: items
        }
      });

    }).catch(function(response) {
      dispatch({
        type: action_types.FETCH_STUFF_REJECTED,
        payload: response
      });
    });
  }
}

Question: Multiple server side dispatches?

Hello,

im currently using CHAIN_API to perform multiple async loads on server side.
For example loadIntroData will perform CHAIN_API with 3 calls:
static fetchData({ store }) {
return store.dispatch( loadIntroData('some') );
}

Is it possible to use multiple store.dispatch calls instead of one chain api?
So something like:

static fetchData({ store }) {
store.dispatch( loadSomething());
store.dispatch( loadSomethingElse());
return store.dispatch( loadIntroData('some') );
}

Thanks

Favicon and static assets

Hello,
What is the good way to add favicon and static folder to the project so that it works correctly both in dev and in production bundle?
Thanks!

How to add Google Analytics?

I tried to add react-ga, but it throws an error, because window is not available on the server. Is it possible to add it only on the client?

Deprecation warnings when trying out template

Hi ,

i'm considering using this template for the current project im starting to work on however, when trying to run it i get deprecation warnings in Chrome.

Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.
Warning: RouterContext: React.createClass is deprecated and will be removed in version 16. Use plain JavaScript classes instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement.

Is there any planned update to fix this?

Thanks

How can I make chainable API call?

I want to do chaining API_CALL actions.

For example, I wrote below code before using this package.

export function signIn(currentUser) {
  return {
    type: actionTypes.SIGN_IN,
    currentUser,
  };
}

export function signInTry(email, password) {
  return dispatch =>
    fetch('/api/login', {
      method: 'post',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        email,
        password,
      }),
    })
    .then(res => handleAjaxError(res))
    .then(res => res.json())
    .then((res) => {
      if (res.access_token) {
        localStorage.clear();
        const userInJson = JSON.stringify(res);
        localStorage.setItem('currentUser', userInJson);
      }
      dispatch(signIn(res));

    })
    .catch((error) => {
      console.log(error);
      return;
    });
}

this http 'post' method has promise callback to execute the signIn action.

however, I can't figure out how to make these things in this system.

help me please 😂

Does not run on Windows

There are a few issues with running this in Windows

  • the start and test scripts set the environment variables in a Unix-only way
  • on Windows, & waits for the process to end before running the next process
  • rm -rf is Unix-only

fixed with #13

Using Link with server side rendering

I wrote a code:

let subHeaders = _.map(this.state.subHeaders, (value, index) => {
            return (
                <div className="col-md-2" key={index}>
                    <Link to={value.route}><Subheader>{value.title}</Subheader></Link>
                </div>
            )
 });

It gives an error:

Unhandled rejection Invariant Violation: Hash history needs a DOM

SO how should I fix this?

call ajax before render (on server-side)

Hi.
Thanks for the great template!

Is it possible to call ajax (using redux of course) before render? on the server-side

I'm using your template and inside component's willMount or didMount I'm dispatching action which will make the ajax, like here: https://github.com/mz026/universal-redux-template/blob/master/app/containers/Questions.js#L14

But when I refresh page then page is firstly generated and rendered without data and after some time data is filled

The same result on /questions page. It's rendered without data and data is filled later.
But is it possible to get and render already filled component?

[QUESTION] Deployment issue

Hi,

We are currently trying to deploy this boilerplate on Windows Azure AppService. Thats basically NodeJs server wrapped into iisnode module(in essence it should function the same as nodejs/express server).

When using steps for deployment, locally it works fine. However, when deployed on Azure app service we are getting the following error:
(function (exports, require, module, __filename, __dirname) { import Express from 'express' ^^^^^^ SyntaxError: Unexpected token import at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10)

For Azure deployment all that needs to be done is to configure web.config file which points to server.js file which should not be the cause of this issue. It seems that this is something to do with babel transpiler missing on deployment machine.

Any idea on how to solve this issue?

Thank you

`WrappedComponent` reference is undefined

When I try to find a component in app/server/server.js, its WrappedComponent reference is always undefined:

let comp = renderProps.components[renderProps.components.length - 1].WrappedComponent;

When trying to output found component, it is logged as:

console.log(renderProps.components[renderProps.components.length - 1])
// [Function: ComponentName]

So the component seems to be found, but there's no way to access its WrappedComponent reference, and, obviously, not possible to access fetchData() method to get data it requires to render with a server.

Tests do not run

npm test has the following error:
Error: cannot resolve path (or pattern) ''app/spec/**/*.test.js''

I am using Windows. It seems like the single quotes are not necessary (and cause issues) around the path/pattern for the test target.

Fixed with #16

./bin/generate throws SyntaxError: Unexpected token import

Hi,

When I try to run ./bin/generate component myNamespace/MyComponent

(function (exports, require, module, __filename, __dirname) { import { execSync } from 'child_process';
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:511:25)
    at loader (/opt/test-react/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/opt/test-react/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)

What do I need in order to have this working ??
I've upgraded NodeJS to:
$ node --version -> v6.0.0

Thanks

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.