├── .babelrc
├── config.js
├── src
├── index.js
├── components
│ ├── Author.js
│ ├── ArticleRow.js
│ ├── ArticleList.js
│ ├── Article.js
│ ├── NewArticleForm.js
│ └── App.js
└── api.js
├── README.md
├── webpack.config.js
├── server.js
├── views
└── index.ejs
├── .eslintrc.js
├── serverRender.js
├── .gitignore
├── sass
└── style.scss
└── package.json
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react", "latest", "stage-2"]
3 | }
4 |
--------------------------------------------------------------------------------
/config.js:
--------------------------------------------------------------------------------
1 | const env = process.env;
2 |
3 | export const nodeEnv = env.NODE_ENV || 'development';
4 |
5 | export default {
6 | port: env.PORT || 8080,
7 | host: env.HOST || 'localhost',
8 | };
9 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 |
4 | import App from './components/App';
5 |
6 | ReactDOM.render(
7 | ,
8 | document.getElementById('root')
9 | );
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## React Blog Example
2 |
3 | A blog example written in React
4 |
5 | ### Development
6 |
7 | ```
8 | npm install
9 | npm run nodemon
10 | npm run webpack
11 | ```
12 |
13 | Server will be running on [http://localhost:8080/](http://localhost:8080/)
14 |
--------------------------------------------------------------------------------
/src/components/Author.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class Author extends React.Component {
4 | render() {
5 | return (
6 |
12 |
{this.props.title}
13 |
14 | {this.props.date}
15 |
16 |
17 |
18 | {this.props.body}
19 |
20 |
21 | );
22 | }
23 | }
24 |
25 | export default Article;
26 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | import config from './config';
2 | import sassMiddleware from 'node-sass-middleware';
3 | import path from 'path';
4 | import express from 'express';
5 | import bodyParser from 'body-parser';
6 |
7 | const server = express();
8 | server.use(bodyParser.json());
9 |
10 | server.use(sassMiddleware({
11 | src: path.join(__dirname, 'sass'),
12 | dest: path.join(__dirname, 'public')
13 | }));
14 |
15 | server.set('view engine', 'ejs');
16 |
17 | server.get('/', (req, res) => {
18 | res.render('index');
19 | });
20 |
21 | server.use(express.static('public'));
22 |
23 | server.listen(config.port, config.host, () => {
24 | console.info('Express listening on port', config.port);
25 | });
26 |
--------------------------------------------------------------------------------
/views/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Loading...
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "parser": 'babel-eslint',
3 | "env": {
4 | "browser": true,
5 | "commonjs": true,
6 | "es6": true,
7 | "node": true
8 | },
9 | "extends": ["eslint:recommended", "plugin:react/recommended"],
10 | "parserOptions": {
11 | "ecmaFeatures": {
12 | "experimentalObjectRestSpread": true,
13 | "jsx": true
14 | },
15 | "sourceType": "module"
16 | },
17 | "plugins": [ "react" ],
18 | "rules": {
19 | "react/prop-types": ["off"],
20 | "indent": ["error", 2],
21 | "linebreak-style": ["error","unix"],
22 | "quotes": ["error","single"],
23 | "semi": ["error","always"],
24 | "no-console": ["warn", { "allow": ["info", "error"] }]
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/serverRender.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOMServer from 'react-dom/server';
3 |
4 | import App from './src/components/App';
5 |
6 | import config from './config';
7 | import axios from 'axios';
8 |
9 | const getApiUrl = () => {
10 | return `${config.serverUrl}/api/items`;
11 | };
12 |
13 | const getInitialData = (apiData) => {
14 | return apiData;
15 | };
16 |
17 | const serverRender = () =>
18 | axios.get(getApiUrl())
19 | .then(resp => {
20 | const initialData = getInitialData(resp.data);
21 | return {
22 | initialMarkup: ReactDOMServer.renderToString(
23 |