Node.js 如何解决;无法获取/quot;AWS部署错误?
我的应用程序在Heroku上部署时运行良好。当我把它推到AWS elastic beanstalk时,它会给我一个页面,上面写着Node.js 如何解决;无法获取/quot;AWS部署错误?,node.js,amazon-web-services,deployment,amazon-elastic-beanstalk,devops,Node.js,Amazon Web Services,Deployment,Amazon Elastic Beanstalk,Devops,我的应用程序在Heroku上部署时运行良好。当我把它推到AWS elastic beanstalk时,它会给我一个页面,上面写着无法获取/ 日志如下所示: ------------------------------------- /var/log/nodejs/nodejs.log ------------------------------------- > react-express-starter@0.1.0 dev /var/app/current > run-p ser
无法获取/
日志如下所示:
-------------------------------------
/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 express = require('express');
var app = express();
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
res.send('hello world');
});
这些都会打印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": {
...
}
}
我尝试将我的脚本更改为
npm run dev
,因为这是我在本地启动它的方式,但这给了我502坏网关
错误。我看到的是,您没有定义路由“/”的响应。
您可以这样做:
-------------------------------------
/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 express = require('express');
var app = express();
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
res.send('hello world');
});
问题是,当您将它推到elastic beanstalk上时,它默认会转到根站点。也许您可以重定向到其他路径以避免这种行为。是的,这是可行的,我想要发送的响应是一个用
React
编写的组件。当我需要该组件并试图将其发回时,它会告诉我,无法在模块之外使用import语句。
。我可以查看您的完整代码吗?也许通过github?一旦你拿到了,让我知道。我会在这里删除我的回购协议。我得到了链接。我没有找到您重新查询组件并发送的位置。我应该看到什么文件?请查看服务器文件夹,然后index.js您真正的错误是run-p:command not found
。我不知道run-p是什么,但看起来您需要安装它。@Jordanm我可以用什么替换它?替换是什么意思?安装工具它给了我一个页面,上面写着无法获取/
当我从/video/token请求一些东西时,它会给我令牌。这是意料之中的。但只有主页没有显示出来。