这是我的package.json:
{
"name": "github-fetcher-fullstack-v2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"react-dev": "webpack -d --watch",
"start": "nodemon server/index.js"
},
"license": "ISC",
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"webpack": "^2.2.1"
},
"dependencies": {
"angular": "^1.6.3",
"animate.css": "^3.7.0",
"bluebird": "^3.5.1",
"body-parser": "^1.17.2",
"bootstrap": "^4.1.3",
"express": "^4.15.0",
"jquery": "^3.1.1",
"moment": "^2.22.2",
"mongoose": "^4.8.6",
"mysql": "^2.13.0",
"popper.js": "^1.14.4",
"react": "^15.4.2",
"react-animated-css": "^1.0.4",
"react-dom": "^15.4.2",
"react-router-dom": "^4.3.1",
"react-simple-popover": "^0.2.4",
"request": "^2.88.0",
"unirest": "^0.5.1"
}
}
您可以使用express.js
在heroku下轻松运行您的项目。您的所有依赖项必须在dependencies
下
的package.json
"scripts": {
"build": "Add yours",
"postinstall": "Same with build",
"start": "node server.js" // Heroku looks for this
},
"dependencies": {
Add all your dependencies here
}
在root下创建server.js文件
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// Your dist folder
app.use(express.static(__dirname + '/react-client/dist/'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/react-client/dist/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);
SynonymFinder.js
.header("X-Mashape-Key", process.env.SYNONYMKEY) // You can use Environment Variables for API Key
在Heroku项目设置页面下将API密钥添加到配置变量