├── README.md ├── .gitignore ├── package.json └── server.js /README.md: -------------------------------------------------------------------------------- 1 | ## Sample React Production Build 2 | Example of the create-react-app production build. 3 | 4 | Read the article for a tutorial on how to build this : 5 | https://medium.com/jeremy-gottfrieds-tech-blog/tutorial-how-to-deploy-a-production-react-app-to-heroku-c4831dfcfa08 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | 11 | # misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | 22 | src/* 23 | public/* 24 | build/static/css/*.map 25 | build/static/js/*.map 26 | static.json 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-world", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "body-parser": "^1.18.3", 7 | "express": "^4.16.3", 8 | "express-favicon": "^2.0.1", 9 | "path": "^0.12.7", 10 | "react": "^16.4.2", 11 | "react-dom": "^16.4.2", 12 | "react-scripts": "1.1.4" 13 | }, 14 | "scripts": { 15 | "start": "node server.js", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test --env=jsdom", 18 | "eject": "react-scripts eject" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const favicon = require('express-favicon'); 3 | const path = require('path'); 4 | const port = process.env.PORT || 8080; 5 | const app = express(); 6 | app.use(favicon(__dirname + '/build/favicon.ico')); 7 | // the __dirname is the current directory from where the script is running 8 | app.use(express.static(__dirname)); 9 | app.use(express.static(path.join(__dirname, 'build'))); 10 | app.get('/ping', function (req, res) { 11 | return res.send('pong'); 12 | }); 13 | app.get('/', function (req, res) { 14 | res.sendFile(path.join(__dirname, 'build', 'index.html')); 15 | }); 16 | 17 | app.listen(port); 18 | --------------------------------------------------------------------------------