Heroku Node.js Error Heroku[router]:at=Error code=H10 desc=";“应用程序崩溃”;方法=获取路径="/&引用;
我试图将我的CRUD节点应用程序部署到Heroku,但无法发送索引页来启动。我已经注释掉了应用程序中处理API的所有内容,只想为索引页提供服务,但由于某些原因无法这样做 注意,如果现在一切可能的话,我不使用也不想使用任何类型的渲染引擎,比如EJS 目录结构:Heroku Node.js Error Heroku[router]:at=Error code=H10 desc=";“应用程序崩溃”;方法=获取路径="/&引用;,node.js,git,express,heroku,Node.js,Git,Express,Heroku,我试图将我的CRUD节点应用程序部署到Heroku,但无法发送索引页来启动。我已经注释掉了应用程序中处理API的所有内容,只想为索引页提供服务,但由于某些原因无法这样做 注意,如果现在一切可能的话,我不使用也不想使用任何类型的渲染引擎,比如EJS 目录结构: /invoicr (root) package.json Procfile server.js /client index.html package.json { "name": "invoicr", "v
/invoicr (root)
package.json
Procfile
server.js
/client
index.html
package.json
{
"name": "invoicr",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"mongoose": "^4.4.7"
}
}
{
"name": "invoicr",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"mongoose": "^4.4.7"
}
}
Procfile(不确定我是否需要它,因为package.json有scripts start命令)
server.js
var port = Number(process.env.PORT || 3000);
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/client'));
app.get('/', function(req, res){
res.sendFile('/index.html'); //I've tried playing around with the path multiple ways and still get errors
});
app.listen(port);
我能够得到一个简单的回答:
var server = http.createServer(function(req, res){
res.writeHead(200, {'Content-Type':'text/html'});
res.end('<h1>World</h1>');
});
server.listen(port);
默认情况下,heroku不会在
devDependencies
安装DEP,您需要将其设置为依赖项
来自Heroku:
Npm从以开始的任何环境变量读取配置
NPM_配置。我们默认设置production=true以安装依赖项
只有如果要安装其他devdependency,可以
禁用此行为:heroku config:set NPM\u config\u PRODUCTION=false
默认情况下,heroku不会在
devDependencies
安装DEP,您需要将其设置为依赖项
来自Heroku:
Npm从以开始的任何环境变量读取配置
NPM_配置。我们默认设置production=true以安装依赖项
只有如果要安装其他devdependency,可以
禁用此行为:heroku config:set NPM\u config\u PRODUCTION=false
您是否尝试过
res.sendFile(uuu dirname+'/index.html')代码>?尝试res.sendFile('index.html',{root:path.join(uu dirname,'client/'))}代码>因此,在我可以执行以下建议之前,Express似乎不会安装在Heroku中<代码>错误:Cannon查找模块“express”
您是否尝试过res.sendFile(uu dirname+'/index.html')代码>?尝试res.sendFile('index.html',{root:path.join(uu dirname,'client/'))}代码>因此,在我可以执行以下建议之前,Express似乎不会安装在Heroku中<代码>错误:Cannon find模块“express”
刚刚发现,我正在查看其他源代码,实现了开发功能,删除了开发,并且真正得到了要部署的东西:)。刚刚发现,我正在查看其他源代码,实现了开发功能,删除了开发,真正得到了要部署的东西:)。
{
"name": "invoicr",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"mongoose": "^4.4.7"
}
}