【发布时间】:2020-04-05 06:43:59
【问题描述】:
我将我的 REACT 应用程序部署到 Heroku 并且一切正常,但是我如何在本地运行它并进行更改?当我使用 npm start 时,它会在端口 8080(这是教程告诉我要使用的端口)上启动,但不会在 3000 上启动。当我到达 localhost:8080 时,我的网站就在那里,但我所做的任何更改都不会显示刷新后。
我只想在本地进行更改,然后将更改重新部署到 Heroku。
Here is my server.js
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);
Here is my package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.9.9",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"aphrodite": "^2.4.0",
"express": "^4.17.1",
"express-favicon": "^2.0.1",
"path": "^0.12.7",
"react": "^16.13.1",
"react-animate-on-scroll": "^2.1.5",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
【问题讨论】:
标签: reactjs heroku deployment