[英]Deploying express node.js project to azure 500 server error
Seem to have tried every available solution even though some claim that Azure have fixed this issue internally, but I cannot get it to work, production deployment gives me a 500 error every time. 似乎已经尝试了所有可用的解决方案,即使有些人声称Azure已在内部修复了此问题,但我无法使其正常工作,生产部署每次都会给我500错误。 Deploying locally works.
在本地部署工作。 Here's my app.js which is basically "out of the box" with express 4.12.2
这是我的app.js,基本上是Express 4.12.2的“开箱即用”
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.set('port', process.env.PORT || 1337);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
I suspect you might be getting this error in the logs. 我怀疑您可能在日志中收到此错误。
Error: ENOENT, open 'D:\\home\\site\\wwwroot\\bin\\views\\layouts\\main.handlebars' at Error (native)
Note the path to the views folder. 请注意views文件夹的路径。
You could try remove the www file. 您可以尝试删除www文件。 Check the last couple of paragraphs in the Express docs on how.
查看Express文档中的最后两段,了解如何操作。
Also I found that adding app.use(express.static('public'));
我也发现添加
app.use(express.static('public'));
is needed if you have resources like images and fonts – it would fail silently otherwise. 如果您拥有图像和字体之类的资源,则需要使用它-否则,它将无提示地失败。
Make sure that your entry point is in the root folder. 确保您的入口点在根文件夹中。
In my case, my entry point was './bin/www', I had to manually move this file to root and update the and sections in the Web.config to get it working. 在我的情况下,我的入口点是“ ./bin/www”,我必须手动将此文件移至根目录并更新Web.config中的和部分,以使其正常工作。
Deploy again after making these changes. 进行这些更改后,请再次部署。
there were a couple solutions provided in the following question 在以下问题中提供了几种解决方案
Azure NodeJS Error: ENOENT, open 'D:\\home\\site\\wwwroot\\bin\\views\\' Azure NodeJS错误:ENOENT,打开“ D:\\ home \\ site \\ wwwroot \\ bin \\ views \\”
for now I simply used the following near the top of app.js process.chdir(__dirname); 现在,我只是在app.js process.chdir(__ dirname);顶部附近使用了以下内容:
I know it is very tricky to handle such scenarios. 我知道处理这种情况非常棘手。
How to check real errors instead of 500 如何检查实际错误而不是500
Good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.