Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit c3325a0

Browse files
author
Maxime Tyler
committed
first commit, publishing to github
0 parents  commit c3325a0

File tree

12 files changed

+233
-0
lines changed

12 files changed

+233
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
dist
4+
.tmp
5+
.DS_Store

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ISO-React: Isomorphic ReactJS Boilerplate
2+
3+
> A complete **[isomorphic](http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/)** Facebook **[React](https://facebook.github.io/react/)** boilerplate.
4+
5+
This project is still under development, contributions are welcome!
6+
7+
## Libraries
8+
9+
* [react](https://facebook.github.io/react/)
10+
* [react-router](https://github.com/rackt/react-router)
11+
* [expressjs](http://expressjs.com/)
12+
* [browserify](http://browserify.org/)
13+
14+
## Installation / How-to
15+
16+
I recommend to use [io.js](https://iojs.org/) to take advantages of `ES6` without `--harmony` flag on `NodeJS`.
17+
18+
It's super easy to do with [nvm](https://github.com/creationix/nvm):
19+
20+
* `$ nvm install iojs`
21+
* `$ nvm use iojs`
22+
* `$ nvm alias default iojs` (to make `node` default to `iojs`)
23+
24+
After that, you will just need to clone the repo and install dependancies:
25+
26+
* `$ git clone https://github.com/iam4x/iso-react.git`
27+
* `$ cd iso-react && npm install`
28+
29+
To run the project:
30+
31+
* `$ npm start`
32+
33+
Open your browser to `http://localhost:3000` and you will see the magic happens! Try to disable JavaScript in your browser, you will still be able to navigate between pages of the application. Enjoy the power of isomorphic applications!
34+
35+
## TODO
36+
37+
* Switch to gulp.
38+
* Flux, Fluxxor or Reflux?
39+
* Add async data retrieval before server rendering, currently all the Ajax calls that will change the state of a components are made on the client after rendering. (Still exploring many way to achieves this, because it breaks the Flux architecture).

app/app.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const Router = require('react-router');
5+
6+
const routes = require('./routes.jsx');
7+
8+
const content = document.getElementById('content');
9+
10+
Router.run(routes, Router.HistoryLocation, (Handler) => {
11+
return React.render(<Handler/>, content);
12+
});

app/components/app.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const {RouteHandler, Link} = require('react-router');
5+
6+
const App = React.createClass({
7+
render() {
8+
return (
9+
<div>
10+
<header>
11+
<ul>
12+
<li><Link to='app'>Home</Link></li>
13+
<li><Link to='guides'>Guides</Link></li>
14+
</ul>
15+
</header>
16+
<RouteHandler/>
17+
</div>
18+
);
19+
}
20+
});
21+
22+
module.exports = App;

app/components/guides.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
5+
const Guides = React.createClass({
6+
render() {
7+
return (
8+
<div>
9+
<h1>Guides</h1>
10+
<p>Coming soon...</p>
11+
</div>
12+
);
13+
}
14+
});
15+
16+
module.exports = Guides;

app/components/home.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
5+
const Home = React.createClass({
6+
render() {
7+
return (
8+
<h1>Home</h1>
9+
);
10+
}
11+
});
12+
13+
module.exports = Home;

app/routes.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const Router = require('react-router');
5+
const {Route, DefaultRoute} = Router;
6+
7+
const App = require('./components/app.jsx');
8+
const Home = require('./components/home.jsx');
9+
const Guides = require('./components/guides.jsx');
10+
11+
module.exports = (
12+
<Route name='app' path='/' handler={App}>
13+
<DefaultRoute name="home" handler={Home} />
14+
<Route name="guides" handler={Guides} />
15+
</Route>
16+
);

package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "iso-react",
3+
"version": "0.0.1",
4+
"description": "An isomorphic ReactJS boilerplate",
5+
"main": "app.js",
6+
"scripts": {
7+
"watch": "./node_modules/.bin/watchify ./app/app.jsx -o ./dist/app.js -v",
8+
"start": "npm run watch & ./node_modules/.bin/nodemon server.js"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/iam4x/iso-react.git"
13+
},
14+
"homepage": "https://github.com/iam4x/iso-react",
15+
"bugs": "https://github.com/iam4x/iso-react/issues",
16+
"author": "iam4x",
17+
"license": "MIT",
18+
"dependencies": {
19+
"express": "^4.11.1",
20+
"express-handlebars": "^1.1.0",
21+
"react": "^0.12.2",
22+
"react-router": "^0.11.6"
23+
},
24+
"devDependencies": {
25+
"browserify": "^8.1.1",
26+
"node-jsx": "^0.12.4",
27+
"nodemon": "^1.3.2",
28+
"reactify": "^1.0.0",
29+
"watchify": "^2.2.1"
30+
},
31+
"browserify": {
32+
"transform": [
33+
[
34+
"reactify",
35+
{
36+
"es6": true
37+
}
38+
]
39+
]
40+
},
41+
"tags": [
42+
"react",
43+
"react-router",
44+
"isomorphic",
45+
"express",
46+
"browserify",
47+
"jsx",
48+
"es6"
49+
],
50+
"keywords": [
51+
"react",
52+
"isomorphic",
53+
"spa",
54+
"ssr",
55+
"express",
56+
"browserify",
57+
"jsx",
58+
"es6"
59+
]
60+
}

router.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const Router = require('react-router');
5+
6+
const routes = require(__dirname + '/app/routes.jsx');
7+
8+
module.exports = (req, res) => {
9+
Router.run(routes, req.url, (Handler) => {
10+
let content = React.renderToString(<Handler/>);
11+
return res.render('main', {content});
12+
});
13+
};

server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
// Install `.jsx` into node
4+
require('node-jsx').install({
5+
extension: '.jsx',
6+
harmony: true
7+
});
8+
9+
const express = require('express');
10+
const exphbs = require('express-handlebars');
11+
12+
const router = require('./router');
13+
14+
const app = express();
15+
16+
app.engine('handlebars', exphbs({defaultLayout: 'index'}));
17+
app.set('view engine', 'handlebars');
18+
19+
app.use('/assets/images', express.static(__dirname + '/app/assets/images'));
20+
app.use('/assets/javascript', express.static(__dirname + '/dist/'));
21+
22+
app.use(router);
23+
app.listen(3000);
24+
25+
console.log('Application started on port 3000');

0 commit comments

Comments
 (0)