Skip to content

Commit 57bc831

Browse files
authored
Merge pull request #36 from combine/release/5.0.0
Release/5.0.0
2 parents 3b94576 + 7be295c commit 57bc831

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+11949
-6810
lines changed

.babelrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
],
66
"plugins": [
77
"react-hot-loader/babel",
8+
"transform-es2015-modules-commonjs",
89
"transform-class-properties",
910
"transform-decorators",
10-
"transform-object-rest-spread",
11-
["resolver", { "resolveDirs": ["common"] }]
11+
"transform-export-extensions",
12+
"transform-object-rest-spread"
1213
]
1314
}

.gitignore

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
npm-error.log
12
.env
23
node_modules
34
npm-debug.log*
45
.DS_Store
56

67
# ignore built static files
7-
dist/
8-
webpack-assets.json
8+
/dist
9+
/webpack-assets.json
10+
11+
# webpack-built server files
12+
server/renderer/*.built.js

README.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@ promise that future updates will not break your existing application.**
1111

1212
## Get started
1313

14-
Install [yarn](https://github.com/yarnpkg/yarn) if you don't have it already:
15-
```
16-
npm install -g yarn
17-
```
18-
19-
Then copy environment variables and edit them if necessary:
14+
Copy environment variables and edit them if necessary:
2015
```
2116
cp .env.example .env
2217
```
2318

2419
Then:
2520
```
26-
yarn install
27-
yarn start
21+
npm install
22+
npm start
2823
```
2924

3025
Direct your browser to `http://localhost:3000`.
3126

3227
For production builds:
3328

3429
```
35-
yarn run prod:start
30+
npm run prod:build
31+
npm run serve
3632
```
3733

38-
Note: pm2 must be installed to run production builds.
34+
For Heroku, simply add a `Procfile`:
35+
```
36+
web: npm run serve
37+
```
3938

4039
## Directory Structure
4140
```
@@ -93,13 +92,13 @@ Make sure you have it installed:
9392
npm install -g mocha
9493
```
9594

96-
Tests should reside alongside the component/module/selector/etc that it is
97-
testing. For example:
95+
Tests should reside in `test/spec` in their appropriate folders:
9896

9997
```
100-
├── reducers
101-
│   ├── todos.js
102-
│   ├── todos.test.js
98+
├── test
99+
│   ├── spec
100+
│   │   ├── api
101+
│   │   │   ├── todos.test.js
103102
```
104103

105104
Tests can be written with ES2015, since it passes through `babel-register`.

client/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import App from 'containers/App';
1010

1111
const history = createHistory();
1212

13-
/* Images
14-
* This space is reserved for images that are required by server rendering,
15-
* e.g. the favicon and any other images that need to be in the base HTML file.
16-
*/
17-
import '../common/images/favicon.png';
18-
1913
// The root element of your app
2014
const rootElement = document.getElementById('app');
2115

@@ -25,7 +19,7 @@ const initialState = window.__INITIAL_STATE__;
2519
const store = configureStore(initialState, history);
2620

2721
const render = (Component) => {
28-
ReactDOM.render(
22+
ReactDOM.hydrate(
2923
<Provider store={store}>
3024
<AppContainer>
3125
<ConnectedRouter history={history}>

common/css/_functions.scss

-1
This file was deleted.

common/css/_variables.scss

-1
This file was deleted.

common/css/base/_fonts.scss

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Import fonts here, from google, or whereever.
2+
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600');

common/css/base/_overrides.scss

Whitespace-only changes.

common/css/base/_styles.scss

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
html, body {
2+
height: 100%;
3+
font-family: 'Open Sans', sans-serif;
4+
5+
p {
6+
font-size: 16px;
7+
line-height: 24px;
8+
}
9+
}
10+
11+
body {
12+
background-color: $white;
13+
}
14+
15+
#app {
16+
height: 100%;
17+
width: 100%;
18+
margin: 0 auto;
19+
}

common/css/base/_vendors.scss

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Import bootstrap-sass as needed
2+
$bootstrap-sass-asset-helper: true;
3+
@import "~bootstrap-sass/assets/stylesheets/bootstrap/variables";
4+
5+
$screen-lg-min: $app-max-width !global;
6+
$container-lg: $app-max-width !global;
7+
8+
@import "~bootstrap-sass/assets/stylesheets/bootstrap/mixins";
9+
@import "~bootstrap-sass/assets/stylesheets/bootstrap/grid";

common/css/base/index.scss

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Vendors and resource files (.e.g. variables, mixins, etc)
2+
@import '../resources/variables';
3+
@import 'vendors';
4+
@import '../resources/mixins';
5+
6+
// The following are non-vendor, non-resource files.
7+
@import 'fonts';
8+
@import 'overrides';
9+
@import 'styles';

common/css/resources/_colors.scss

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$white: #fff;
2+
$dark-gray: #333;

common/css/resources/_mixins.scss

Whitespace-only changes.

common/css/resources/_variables.scss

Whitespace-only changes.
File renamed without changes.

common/js/actions/todos.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
ADD_TODO, REMOVE_TODO, TOGGLE_TODO,
33
FETCH_TODOS_REQUEST, FETCH_TODOS_SUCCESS, FETCH_TODOS_FAILURE
44
} from 'constants/index';
5-
import { fetch } from 'lib/api';
6-
import generateActionCreator from 'lib/generateActionCreator';
5+
import api from 'helper/api';
6+
import generateActionCreator from 'helper/generateActionCreator';
77

88
export const addTodo = generateActionCreator(ADD_TODO, 'text');
99
export const removeTodo = generateActionCreator(REMOVE_TODO, 'id');
@@ -14,15 +14,19 @@ export const fetchTodosSuccess = generateActionCreator(FETCH_TODOS_SUCCESS, 'tod
1414
export const fetchTodosFailure = generateActionCreator(FETCH_TODOS_FAILURE, 'error');
1515

1616
export const fetchTodos = () => {
17-
return async (dispatch) => {
17+
return (dispatch) => {
1818
dispatch(fetchTodosRequest());
1919

20-
try {
21-
const response = await fetch('/api/todos', { method: 'GET' });
22-
const todos = await response.json();
23-
dispatch(fetchTodosSuccess(todos));
24-
} catch (e) {
25-
dispatch(fetchTodosFailure(e.message));
26-
}
20+
return api.get('/api/todos')
21+
.then(todos => {
22+
dispatch(fetchTodosSuccess(todos));
23+
24+
return Promise.resolve(todos);
25+
})
26+
.catch(error => {
27+
dispatch(fetchTodosFailure(error));
28+
29+
return Promise.reject(error);
30+
});
2731
};
2832
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import { Route } from 'react-router';
3+
4+
const RouteWithSubRoutes = props => {
5+
const {
6+
path,
7+
computedMatch,
8+
component: Component,
9+
routes,
10+
restProps
11+
} = props;
12+
13+
return (
14+
<Route
15+
path={path}
16+
render={props => {
17+
// pass the sub-routes down to keep nesting
18+
return (
19+
<Component
20+
{...props}
21+
{...restProps}
22+
match={computedMatch}
23+
routes={routes}
24+
/>
25+
);
26+
}}
27+
/>
28+
);
29+
};
30+
31+
export default RouteWithSubRoutes;

common/js/components/common/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { default as ErrorPage } from './ErrorPage';
2+
export { default as Footer } from './Footer';
3+
export { default as Header } from './Header';
4+
export { default as RouteWithSubRoutes } from './RouteWithSubRoutes';

common/js/containers/App/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import React from 'react';
2-
import { Switch, Route } from 'react-router-dom';
2+
import { Switch } from 'react-router-dom';
3+
import { RouteWithSubRoutes } from 'components/common';
34
import { Container } from 'semantic-ui-react';
4-
import Header from 'components/Header';
5-
import Footer from 'components/Footer';
5+
import { Header, Footer } from 'components/common';
66
import routes from 'routes';
77

88
const App = () => (
99
<Container fluid={false}>
1010
<Header />
1111
<Switch>
12-
{routes.map(route => <Route key={route.path} {...route} />)}
12+
{routes.map(route => (
13+
<RouteWithSubRoutes key={route.path} {...route} />
14+
))}
1315
</Switch>
1416
<Footer />
1517
</Container>

common/js/containers/Home/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react';
2+
import { Link } from 'react-router-dom';
23
import { Helmet } from 'react-helmet';
34
import css from './index.scss';
45

@@ -10,6 +11,15 @@ export default class HomeContainer extends Component {
1011
<title>Home</title>
1112
</Helmet>
1213
<h1>It Works!</h1>
14+
<p>
15+
You've successfully started up your first universally rendered react
16+
and redux app.<br />
17+
Hint: Try View Source on this page to see that it was
18+
rendered on the server as well.
19+
</p>
20+
<p>
21+
Check out the <Link to='/todos'>todos list</Link>.
22+
</p>
1323
</div>
1424
);
1525
}

common/js/containers/Home/index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.home {
22
h1 {
3-
font-size: 50px;
3+
font-size: 30px;
44
}
55
}

common/js/helper/api.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import axios from 'axios';
2+
3+
const headers = { 'Content-Type': 'application/json' };
4+
const baseURL = process.env.APPLICATION_BASE_URL || '';
5+
const api = axios.create({ baseURL, headers, timeout: 200000 });
6+
7+
api.interceptors.response.use(
8+
(response) => Promise.resolve(response.data) ,
9+
(err) => Promise.reject(err.response.data)
10+
);
11+
12+
module.exports = api;

common/js/lib/api.js

-6
This file was deleted.

common/layouts/server.html renamed to common/templates/layouts/application.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= helmet.title %>
55
<meta charset="utf-8" />
66
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width height=device-height" />
7-
<link rel="shortcut icon" type="image/x-icon" href="<%= favicon %>">
7+
<link rel="shortcut icon" type="image/x-icon" href="/dist/images/favicon.png">
88
<link type="text/css" rel="stylesheet" href="<%= vendorCss %>" />
99
<link type="text/css" rel="stylesheet" href="<%= appCss %>" />
1010
</head>

nodemon.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"server/**/*.js",
44
"server/**/*.json",
55
"common/js/**/*.js",
6-
"common/layouts/server.html"
6+
"common/templates/**/*.html"
77
]
88
}

0 commit comments

Comments
 (0)