initial commit
This commit is contained in:
commit
4b60ece582
327 changed files with 28286 additions and 0 deletions
6
magnus/middleware/CMakeLists.txt
Normal file
6
magnus/middleware/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(errorHandler.js errorHandler.js)
|
||||
configure_file(reply.js reply.js)
|
||||
configure_file(notFound.js notFound.js)
|
||||
configure_file(pageInMagnus.js pageInMagnus.js)
|
36
magnus/middleware/errorHandler.js
Normal file
36
magnus/middleware/errorHandler.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var defaultHandler = require("errorhandler");
|
||||
|
||||
var config = require("../config");
|
||||
var log = require("../lib/log");
|
||||
var HttpError = require("../lib/httpError");
|
||||
|
||||
function errorHandler(err, req, res, next) {
|
||||
if (typeof err == "number") {
|
||||
err = new HttpError(err);
|
||||
}
|
||||
|
||||
if (err instanceof HttpError) {
|
||||
sendHttpError(err, res, req);
|
||||
} else {
|
||||
if (config.get("build") === "debug") {
|
||||
var handler = defaultHandler();
|
||||
handler(err, req, res, next);
|
||||
} else {
|
||||
log.error(err);
|
||||
err = new HttpError(500);
|
||||
sendHttpError(err, res, req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendHttpError(error, res, req) {
|
||||
res.status(error.status);
|
||||
//if (req.headers['x-requested-with'] == 'XMLHttpRequest') {
|
||||
// res.json(error);
|
||||
//} else {
|
||||
// res.reply(error);
|
||||
//}
|
||||
res.reply(error);
|
||||
}
|
||||
|
||||
module.exports = errorHandler;
|
6
magnus/middleware/notFound.js
Normal file
6
magnus/middleware/notFound.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
"use strict";
|
||||
var HttpError = require("../lib/httpError");
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
return next(new HttpError(404, 'Page not found!'));
|
||||
};
|
9
magnus/middleware/pageInMagnus.js
Normal file
9
magnus/middleware/pageInMagnus.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
"use strict";
|
||||
module.exports = function(req, res, next) {
|
||||
if (global.magnus.hasPage(req.path)) {
|
||||
res.reply("Building " + req.path + "...");
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
8
magnus/middleware/reply.js
Normal file
8
magnus/middleware/reply.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
"use strict";
|
||||
var path = require("path");
|
||||
module.exports = function(req, res, next) {
|
||||
res.reply = function(info) {
|
||||
this.render("index", {info: info});
|
||||
};
|
||||
next();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue