使用NodeJS时出现503错误。我的函数可以在localhost
中工作,但在远程服务器上却收到503错误。
功能:
function postEdit(request, response) {
var updatedParams = request.body.updatedParams,
blockName = request.params.blockname,
primaryColor, secondaryColor, variables, scssStr;
if (blockName === 'themeparam') {
primaryColor = updatedParams.primary_color;
secondaryColor = updatedParams.secondary_color;
variables = updatedParams.variables;
if (primaryColor || secondaryColor || variables) {
scssStr = fs.readFileSync('./public/sass/_functions.scss', 'utf8');
scssStr += fs.readFileSync('./public/sass/_settings.scss', 'utf8');
if (primaryColor) {
scssStr = scssStr.replace(/\$main-color:.+;/g, '$main-color: ' + primaryColor + ';');
}
if (secondaryColor) {
scssStr = scssStr.replace(/\$secondary-color:.+;/g, '$secondary-color: ' + secondaryColor + ';');
}
scssStr += fs.readFileSync('./public/sass/app.scss', 'utf8');
scssStr = scssStr.replace(/@import.+;/g, '');
if (variables) {
scssStr += variables;
}
fs.readdir('./public/sass/components', function(err, files) {
files.forEach(function(file) {
scssStr += fs.readFileSync('./public/sass/components/' + file, 'utf8');
});
fs.readdir('./public/sass/shortcodes', function(err, shortcodeFiles) {
shortcodeFiles.forEach(function(shortcodeFile) {
scssStr += fs.readFileSync('./public/sass/shortcodes/' + shortcodeFile, 'utf8');
});
fs.writeFileSync('./public/uploads/theme.scss', scssStr);
sass.render({
file: './public/uploads/theme.scss'
}, function(err, result) {
if (err) {
console.log(err);
}
fs.writeFileSync('./public/uploads/theme.css', result.css);
});
});
});
} else {
fs.stat('./public/uploads/theme.scss', function(err) {
if (err) {
console.log(err);
}
if (!err) {
fs.unlinkSync('./public/uploads/theme.scss');
fs.unlinkSync('./public/uploads/theme.css');
}
});
}
}
if (blockName === 'robotparam') {
fs.writeFileSync('./public/robots.txt', updatedParams.robot);
}
editJsonFile(request, response, './configs/options.json', function(options) {
_.forEach(updatedParams, function(value, name) {
var blockParam = _.find(options.blocks, { name: blockName }),
param = _.find(blockParam.params, { name: name });
param.value = value;
});
}, OptionController.baseUrl + '/edit/block/' + blockName);
}
function editJsonFile(request, response, jsonFile, updater, redirectUrl) {
fs.readFile(jsonFile, 'utf8', function(err, data) {
if (err) {
throw err;
}
var options = JSON.parse(data);
updater(options);
fs.writeFile(jsonFile, JSON.stringify(options, null, 4), function(err) {
if (err) {
throw err;
}
request.flash('success', 'Done !');
response.redirect(redirectUrl);
});
});
}
错误503:
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.4.7 (Ubuntu) Server at ****** Port 443
是否有解决方案来获取错误消息以查找问题?