Мое приложение работает нормально, когда я развернул его на Heroku
. Когда я пу sh это AWS elasti c beanstalk, это дает мне страницу, которая говорит 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 раз.
пакет. 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": {
...
}
}
сервер -> индекс. 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
ошибку.