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

Commit 6f73fa4

Browse files
committed
Complete Lesson 11: Productionish Server
1 parent 920ca5d commit 6f73fa4

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/home/rich/.nvm/versions/node/v5.11.1/bin/node',
3+
1 verbose cli '/home/rich/.nvm/versions/node/v5.11.1/bin/npm',
4+
1 verbose cli 'run',
5+
1 verbose cli 'start:prod' ]
6+
2 info using [email protected]
7+
3 info using [email protected]
8+
4 verbose run-script [ 'prestart:prod', 'start:prod', 'poststart:prod' ]
9+
5 info lifecycle [email protected]~prestart:prod: [email protected]
10+
6 silly lifecycle [email protected]~prestart:prod: no script for prestart:prod, continuing
11+
7 info lifecycle [email protected]~start:prod: [email protected]
12+
8 verbose lifecycle [email protected]~start:prod: unsafe-perm in lifecycle true
13+
9 verbose lifecycle [email protected]~start:prod: PATH: /home/rich/.nvm/versions/node/v5.11.1/lib/node_modules/npm/bin/node-gyp-bin:/home/rich/Dev_Academy/02_phase_two/05_week_five/react-router-tutorial/lessons/01-setting-up/node_modules/.bin:/home/rich/.nvm/versions/node/v5.11.1/bin:/home/rich/.nvm/versions/node/v5.11.1/lib/node_modules/npm/bin/node-gyp-bin:/home/rich/Dev_Academy/02_phase_two/05_week_five/react-router-tutorial/lessons/01-setting-up/node_modules/.bin:/home/rich/.nvm/versions/node/v5.11.1/bin:/home/rich/.nvm/versions/node/v5.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
14+
10 verbose lifecycle [email protected]~start:prod: CWD: /home/rich/Dev_Academy/02_phase_two/05_week_five/react-router-tutorial/lessons/01-setting-up
15+
11 silly lifecycle [email protected]~start:prod: Args: [ '-c', 'webpack && node server.js' ]
16+
12 silly lifecycle [email protected]~start:prod: Returned: code: 255 signal: null
17+
13 info lifecycle [email protected]~start:prod: Failed to exec start:prod script
18+
14 verbose stack Error: [email protected] start:prod: `webpack && node server.js`
19+
14 verbose stack Exit status 255
20+
14 verbose stack at EventEmitter.<anonymous> (/home/rich/.nvm/versions/node/v5.11.1/lib/node_modules/npm/lib/utils/lifecycle.js:239:16)
21+
14 verbose stack at emitTwo (events.js:100:13)
22+
14 verbose stack at EventEmitter.emit (events.js:185:7)
23+
14 verbose stack at ChildProcess.<anonymous> (/home/rich/.nvm/versions/node/v5.11.1/lib/node_modules/npm/lib/utils/spawn.js:24:14)
24+
14 verbose stack at emitTwo (events.js:100:13)
25+
14 verbose stack at ChildProcess.emit (events.js:185:7)
26+
14 verbose stack at maybeClose (internal/child_process.js:850:16)
27+
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
28+
15 verbose pkgid [email protected]
29+
16 verbose cwd /home/rich/Dev_Academy/02_phase_two/05_week_five/react-router-tutorial/lessons/01-setting-up
30+
17 error Linux 3.19.0-32-generic
31+
18 error argv "/home/rich/.nvm/versions/node/v5.11.1/bin/node" "/home/rich/.nvm/versions/node/v5.11.1/bin/npm" "run" "start:prod"
32+
19 error node v5.11.1
33+
20 error npm v3.8.6
34+
21 error code ELIFECYCLE
35+
22 error [email protected] start:prod: `webpack && node server.js`
36+
22 error Exit status 255
37+
23 error Failed at the [email protected] start:prod script 'webpack && node server.js'.
38+
23 error Make sure you have the latest version of node.js and npm installed.
39+
23 error If you do, this is most likely a problem with the tutorial package,
40+
23 error not with npm itself.
41+
23 error Tell the author that this fails on your system:
42+
23 error webpack && node server.js
43+
23 error You can get information on how to open an issue for this project with:
44+
23 error npm bugs tutorial
45+
23 error Or if that isn't available, you can get their info via:
46+
23 error npm owner ls tutorial
47+
23 error There is likely additional logging output above.
48+
24 verbose exit [ 1, true ]

lessons/01-setting-up/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"start": "webpack-dev-server --inline --content-base . --history-api-fallback"
7+
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
8+
"start:dev": "webpack-dev-server --inline --content-base public --history-api-fallback",
9+
"start:prod": "webpack && node server.js"
810
},
911
"author": "",
1012
"license": "ISC",
1113
"dependencies": {
14+
"compression": "^1.6.2",
15+
"express": "^4.14.0",
16+
"if-env": "^1.0.0",
1217
"react": "^0.14.7",
1318
"react-dom": "^0.14.7",
1419
"react-router": "^2.0.0"
File renamed without changes.
File renamed without changes.

lessons/01-setting-up/server.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var express = require('express')
2+
var path = require('path')
3+
var compression = require('compression')
4+
5+
var app = express()
6+
7+
app.use(compression())
8+
9+
// serve our static stuff like index.css
10+
app.use(express.static(path.join(__dirname, 'public')))
11+
12+
// send all requests to index.html so browserHistory in React Router works
13+
app.get('*', function (req, res) {
14+
res.sendFile(path.join(__dirname, 'public', 'index.html'))
15+
})
16+
17+
var PORT = process.env.PORT || 8080
18+
app.listen(PORT, function() {
19+
console.log('Production Express server running at localhost:' + PORT)
20+
})

lessons/01-setting-up/webpack.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
var webpack = require('webpack')
2+
13
module.exports = {
24
entry: './index.js',
35

46
output: {
5-
filename: 'bundle.js',
6-
publicPath: ''
7+
path: 'public'
78
},
89

10+
plugins: process.env.NODE_ENV === 'production' ? [
11+
new webpack.optimize.DedupePlugin(),
12+
new webpack.optimize.OccurrenceOrderPlugin(),
13+
new webpack.optimize.UglifyJsPlugin()
14+
] : [],
15+
916
module: {
1017
loaders: [
1118
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' }

0 commit comments

Comments
 (0)