Compare commits
8 Commits
package-lo
...
multi-proc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
838b163487 | ||
|
|
d88e7b287c | ||
|
|
e7a5eb4ca5 | ||
|
|
342b99fb18 | ||
|
|
2b17c2aa4a | ||
|
|
71e2496d10 | ||
|
|
80bbce5c5d | ||
|
|
cace55f3b7 |
@@ -10,7 +10,7 @@ To deploy a frontend-only React app, use the static-site optimized
|
|||||||
|
|
||||||
## Design Points
|
## Design Points
|
||||||
|
|
||||||
A combo of two npm projects, the backend server and the frontend UI. So there are two `package.json` configs.
|
A combo of two npm projects, the backend server and the frontend UI. So there are two `package.json` configs and thereforce two places to run `npm` commands:
|
||||||
|
|
||||||
1. [`package.json`](package.json) for [Node server](server/) & [Heroku deploy](https://devcenter.heroku.com/categories/deployment)
|
1. [`package.json`](package.json) for [Node server](server/) & [Heroku deploy](https://devcenter.heroku.com/categories/deployment)
|
||||||
* `heroku-postbuild` script compiles the webpack bundle during deploy
|
* `heroku-postbuild` script compiles the webpack bundle during deploy
|
||||||
@@ -18,6 +18,7 @@ A combo of two npm projects, the backend server and the frontend UI. So there ar
|
|||||||
2. [`react-ui/package.json`](react-ui/package.json) for [React web UI](react-ui/)
|
2. [`react-ui/package.json`](react-ui/package.json) for [React web UI](react-ui/)
|
||||||
* generated by [create-react-app](https://github.com/facebookincubator/create-react-app)
|
* generated by [create-react-app](https://github.com/facebookincubator/create-react-app)
|
||||||
|
|
||||||
|
Includes a minimal [Node Cluster](https://nodejs.org/docs/latest-v8.x/api/cluster.html) [implementation](server/index.js) to parallelize the single-threaded Node process across the available CPU cores.
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@ This deployment will automatically:
|
|||||||
* serves `../react-ui/build/` as static files
|
* serves `../react-ui/build/` as static files
|
||||||
* customize by adding API, proxy, or route handlers/redirectors
|
* customize by adding API, proxy, or route handlers/redirectors
|
||||||
|
|
||||||
|
⚠️ Using npm 5’s new `package-lock.json`? We resolved a compatibility issue. See [PR](https://github.com/mars/heroku-cra-node/pull/10) for more details.
|
||||||
|
|
||||||
👓 More about [deploying to Heroku](https://devcenter.heroku.com/categories/deployment).
|
👓 More about [deploying to Heroku](https://devcenter.heroku.com/categories/deployment).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
app.json
Normal file
21
app.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "heroku-cra-node",
|
||||||
|
"description": "web app made of create-react-app UI + Node API",
|
||||||
|
"scripts": {
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
},
|
||||||
|
"formation": {
|
||||||
|
"web": {
|
||||||
|
"quantity": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"addons": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"buildpacks": [
|
||||||
|
{
|
||||||
|
"url": "heroku/nodejs"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "How to use create-react-app with a custom Node API on Heroku",
|
"description": "How to use create-react-app with a custom Node API on Heroku",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "6.11.x"
|
"node": "8.9.x"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server",
|
"start": "node server",
|
||||||
|
|||||||
9432
react-ui/package-lock.json
generated
9432
react-ui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,11 +3,11 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"react-scripts": "0.9.5"
|
"react-scripts": "^1.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^15.4.2",
|
"react": "^16.2.0",
|
||||||
"react-dom": "^15.4.2"
|
"react-dom": "^16.2.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const cluster = require('cluster');
|
||||||
|
const numCPUs = require('os').cpus().length;
|
||||||
|
|
||||||
const app = express();
|
|
||||||
const PORT = process.env.PORT || 5000;
|
const PORT = process.env.PORT || 5000;
|
||||||
|
|
||||||
|
// Multi-process to utilize all CPU cores.
|
||||||
|
if (cluster.isMaster) {
|
||||||
|
console.error(`Node cluster master ${process.pid} is running`);
|
||||||
|
|
||||||
|
// Fork workers.
|
||||||
|
for (let i = 0; i < numCPUs; i++) {
|
||||||
|
cluster.fork();
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster.on('exit', (worker, code, signal) => {
|
||||||
|
console.error(`Node cluster worker ${worker.process.pid} exited: code ${code}, signal ${signal}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const app = express();
|
||||||
|
|
||||||
// Priority serve any static files.
|
// Priority serve any static files.
|
||||||
app.use(express.static(path.resolve(__dirname, '../react-ui/build')));
|
app.use(express.static(path.resolve(__dirname, '../react-ui/build')));
|
||||||
|
|
||||||
@@ -19,5 +36,6 @@ app.get('*', function(request, response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, function () {
|
app.listen(PORT, function () {
|
||||||
console.log(`Listening on port ${PORT}`);
|
console.error(`Node cluster worker ${process.pid}: listening on port ${PORT}`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user