Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 18222db

Browse files
authored
Merge pull request #25 from RyanCCollins/feat_rc_server_setup
Feat rc server setup
2 parents cc2a3cc + d62e7a3 commit 18222db

11 files changed

+292
-20
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node server.js

README.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You can read more about the organizational strategy used in this app in [this Me
99
We incorporate an ESLint configuration and follow strictly the [AirBnb JS & JSX style guides](https://github.com/airbnb/javascript).
1010

1111
# What is Feature First?
12-
In most projects and frameworks, files are organized in a File type first fashion. For example, your tests exist in a test folder, your styles in a styles folder. This boilerplate takes a different approach.
12+
In most projects and frameworks, files are organized in a File type first fashion. For example, your tests exist in a test folder, your styles in a styles folder. This boilerplate takes a different approach.
1313

1414
We encourage encapsulation of features by asking that you organize each feature into a seperate folder (feature-first). In React, this means that your containers and components exist in their own folders, along with literally every other file that pertains to that one component. Your actions, reducers, tests, styles, and everything else are all internal to the component they represent. By decoupling your features from the rest of your app, you set yourself up to reuse your UI components in future projects. You can thank us later!
1515

@@ -40,13 +40,16 @@ To try the example application out or to use the project, follow the instruction
4040

4141
npm run start
4242

43-
Development server should be running at http://localhost:8080/
43+
Your app will be served at: http://0.0.0.0:1337/
4444

45-
4. **Make build**
45+
## Deployment
46+
In order to deploy the app, a demo express server setup has been included. If you peak inside the server folder, you will see an example setup. The public folder includes all of the files that are generated when running the: `npm run deploy` script. This includes the production minified bundle.js, index.html and an app folder that includes all image assets.
4647

47-
npm run build
48+
The express server can be run with `npm run serve:bundle`. This will start a static express server and serve the generated assets, just like you would in production. A Procfile is included, that will run the node server on [Heroku](https://heroku.com) automatically if you push your project to Heroku after running the `npm run deploy` command.
4849

49-
### File Structure
50+
NOTE: the deployment script will place all your generated assets in the `server/public` folder, where they can be served in production.
51+
52+
## File Structure
5053
* Some files left out for brevity. Please reference the files in the [Scalable React Boilerplate](https://github.com/RyanCCollins/feature-first-react-boilerplate) project for an example of the file structure. The application will ultimately be in use in a production web application project and more info will be posted here when we have production level examples.
5154
```
5255
.
@@ -93,30 +96,31 @@ To try the example application out or to use the project, follow the instruction
9396

9497
## Scripts
9598
- **npm run setup**
96-
97-
Installs the application's dependencies
99+
+ Installs the application's dependencies
98100

99101
- **npm run test**
102+
+ Runs unit tests
100103

101-
Runs unit tests
102104
- **npm run test:watch**
105+
+ Watches for changes to run unit tests
103106

104-
Watches for changes to run unit tests
105107
- **npm run build**
108+
+ Bundles the application
106109

107-
Bundles the application
108110
- **npm run dev**
111+
+ Starts webpack development server
109112

110-
Starts webpack development server
111113
- **npm run lint**
114+
+ Runs the linter
112115

113-
Runs the linter
114116
- **npm run deploy**
117+
+ Creates the production ready files within the `/server/public` folder
115118

116-
Creates the production ready files
117119
- **npm run clean**
120+
+ Removes the bundled code and the production ready files
118121

119-
Removes the bundled code and the production ready files
122+
- **npm run serve:bundle**
123+
+ Serve production assets from the `/server/public` folder.
120124

121125
## Generators
122126
The boilerplate contains generators for easy project scaffolding. At the moment, the generator has the following scaffold generating commands built in:
@@ -155,7 +159,7 @@ where <type_of_component> is one of: component, container or page.
155159

156160
The generators use the same feature-first file organization as the rest of the project, encapsulating components within their own folder.
157161

158-
#### **Gotchas**
162+
### **Gotchas**
159163
In order to get the import / export to work, the generator does some pattern matching of the comments in the files to place the new imports. Just don't delete the comments within the root level index.js file in each directory and things will work fine!
160164

161165
From `app/src/container/index.js` or `app/src/component/index.js`
@@ -226,6 +230,8 @@ which will pick up any file with the .test.js postfix and run it through Karma /
226230
* [x] Add [Grommet](grommet.io) as an optional starter component library
227231
* [x] Add Webpack stats plugin
228232
* [x] Dogfood the project and iterate on suggestions
233+
* [x] Setup production server configuration
234+
* [ ] Add Jest as testing utility
229235
* [ ] Create Docker container & automation scripts
230236
* [ ] Write wiki / other documentation
231237

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!doctype html>
2+
<!doctype html>
23
<html lang="en">
34
<head>
45
<meta charset="UTF-8">
56
<meta http-equiv=X-UA-Compatible content="IE=edge">
67
<meta name=viewport content="width=device-width,initial-scale=1">
78
<title>Scalable React Boilerplate</title>
8-
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css" rel="stylesheet">
99
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
1010
</head>
1111
<body>

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
"generate:container": "plop --plopfile config/generators/index.js container",
2626
"generate:page": "plop --plopfile config/generators/index.js page",
2727
"lint": "eslint . --ext .js --ext .jsx; exit 0",
28-
"deploy": "NODE_ENV=production webpack -p",
28+
"deploy": "cross-env NODE_ENV=production webpack -p",
2929
"start": "npm run dev",
3030
"clean": "rm -rf app/dist app/build",
31-
"setup": "npm install"
31+
"setup": "npm install",
32+
"serve:bundle": "cross-env NODE_ENV=production PORT=1337 node server.js"
3233
},
3334
"repository": {
3435
"type": "git",
@@ -62,6 +63,7 @@
6263
"babel-preset-stage-0": "^6.3.13",
6364
"components": "^0.1.0",
6465
"css-loader": "^0.23.0",
66+
"express": "^4.14.0",
6567
"expect": "^1.20.2",
6668
"expect-jsx": "^2.6.0",
6769
"file-loader": "^0.9.0",

server.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("babel-core/register");
2+
var app = require('./server/app');

server/app.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable */
2+
const isDeveloping = process.env.NODE_ENV !== 'production';
3+
const port = isDeveloping ? 1337 : process.env.PORT;
4+
const path = require('path');
5+
const express = require('express');
6+
const app = express();
7+
8+
app.use(express.static(__dirname + '/public'));
9+
app.get('*', (req, res) => {
10+
res.sendFile(path.join(__dirname, 'public/index.html'));
11+
});
12+
13+
app.listen(port, '0.0.0.0', (err) => {
14+
if (err) {
15+
return console.warn(err);
16+
}
17+
return console.info(`==> 😎 Listening on port ${port}. Open http://0.0.0.0:${port}/ in your browser.`);
18+
});
19+
/* eslint-enable */
Loading

server/public/bundle.js

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/public/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<!doctype html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv=X-UA-Compatible content="IE=edge">
7+
<meta name=viewport content="width=device-width,initial-scale=1">
8+
<title>Scalable React Boilerplate</title>
9+
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Raleway:400,300,700|Lato:400,300,700' rel='stylesheet' type='text/css'>
10+
</head>
11+
<body>
12+
<!-- The app will bootstrap into this div -->
13+
<div id="app"></div>
14+
<script src="/app/build/bundle.js"></script>
15+
<script type="text/javascript" src="/bundle.js"></script></body>
16+
</html>

server/public/stats.html

+189
Large diffs are not rendered by default.

webpack.config.babel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Visualizer from 'webpack-visualizer-plugin';
66
const ROOT_PATH = path.resolve(__dirname);
77

88
const env = process.env.NODE_ENV || 'development';
9-
const PORT = process.env.PORT || 8080;
9+
const PORT = process.env.PORT || 1337;
1010
const HOST = '0.0.0.0'; // Set to localhost if need be.
1111

1212
module.exports = {
@@ -76,7 +76,7 @@ module.exports = {
7676
},
7777
},
7878
output: {
79-
path: process.env.NODE_ENV === 'production' ? path.resolve(ROOT_PATH, 'app/dist') : path.resolve(ROOT_PATH, 'app/build'),
79+
path: process.env.NODE_ENV === 'production' ? path.resolve(ROOT_PATH, 'server/public') : path.resolve(ROOT_PATH, 'app/build'),
8080
publicPath: '/',
8181
filename: 'bundle.js',
8282
},

0 commit comments

Comments
 (0)