【发布时间】:2020-07-19 22:17:21
【问题描述】:
当我在Heroku 上部署应用程序时,它运行良好。当我将它推送到 AWS 弹性豆茎时,它会给我一个页面,上面写着Cannot Get /。
日志如下所示:
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
> react-express-starter@0.1.0 dev /var/app/current
> run-p server start
sh: run-p: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! react-express-starter@0.1.0 dev: `run-p server start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the react-express-starter@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Express server is running on localhost:8081
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2020/04/07 03:46:43 [error] 5546#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 206.188.72.122, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com"
2020/04/07 03:46:44 [error] 5546#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 206.188.72.122, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com", referrer: "http://reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com/"
2020/04/07 04:04:00 [error] 5546#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 206.188.72.122, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com"
2020/04/07 04:04:00 [error] 5546#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 206.188.72.122, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com", referrer: "http://reacttwilio-env.eba-ugm2xpnb.us-east-2.elasticbeanstalk.com/"
这些会打印大约 10 次。
package.json
{
"name": "react-express-starter",
"version": "0.1.0",
"private": true,
"dependencies": {
...
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"server": "node-env-run server --exec nodemon | pino-colada",
"server:prod": "node server",
"dev": "server start"
},
"proxy": "http://localhost:3001",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"engines": {
"node": "12.x"
},
"devDependencies": {
...
}
}
服务器 -> index.js
app.use(express.static(path.join(__dirname, "..", "build")));
const sendTokenResponse = (token, res) => {
res.set("Content-Type", "application/json");
res.send(
JSON.stringify({
token: token.toJwt()
})
);
};
app.get("/api/greeting", (req, res) => {
const name = req.query.name || "World";
res.setHeader("Content-Type", "application/json");
res.send(JSON.stringify({ greeting: `Hello ${name}!` }));
});
app.get("/video/token", (req, res) => {
const identity = req.query.identity;
const room = req.query.room;
const token = videoToken(identity, room, config);
sendTokenResponse(token, res);
});
app.post("/video/token", (req, res) => {
const identity = req.body.identity;
const room = req.body.room;
const token = videoToken(identity, room, config);
sendTokenResponse(token, res);
});
app.listen(config.port, () =>
console.log(`Express server is running on localhost:${config.port}`)
);
我尝试将我的脚本更改为npm run dev,因为这是我在本地启动它的方式,但这给了我502 bad gateway 错误。
【问题讨论】:
-
你真正的错误是这个
run-p: command not found。我不知道run-p是什么,但是看起来你需要安装它。 -
@Jordanm 我可以用什么代替它?
-
替换是什么意思?安装工具
-
它给了我一个页面,上面写着
Cannot Get / -
当我从 /video/token 请求某些东西时,它会给我令牌。这是预期的。但是只有主页没有显示。
标签: node.js amazon-web-services deployment amazon-elastic-beanstalk devops