问题描述
似乎有人尝试过所有可用的解决方案,尽管有人声称Azure已在内部解决了此问题,但我无法使其正常工作,生产部署每次都会给我500错误.在本地部署工作.这是我的app.js,基本上是Express 4.12.2的开箱即用"
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. Deploying locally works. Here's my app.js which is basically "out of the box" with 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.
错误:ENOENT,打开'D:\ home \ site \ wwwroot \ bin \ views \ layouts \ main.handlebars'错误(本机)
记下views文件夹的路径.
Note the path to the views folder.
您可以尝试删除www文件.查看快速文档中的最后几段.
You could try remove the www file. Check the last couple of paragraphs in the Express docs on how.
我还发现,如果您拥有图像和字体之类的资源,则需要添加 app.use(express.static('public'));
–否则将以静默方式失败.
Also I found that adding app.use(express.static('public'));
is needed if you have resources like images and fonts – it would fail silently otherwise.
这篇关于将Express Node.js项目部署到Azure 500服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!