@@ -20,7 +20,7 @@ | |||
"session_timeout": 1800000, | |||
"dir": { | |||
"imgs": "imgs", | |||
"web": "web | |||
"web": "web" | |||
}, | |||
"debug": false, | |||
"max_runs": 9999, |
@@ -2,6 +2,7 @@ var formidable = require("formidable"); | |||
var crypto = require("crypto"); | |||
var zlib = require("zlib"); | |||
var fs = require("fs"); | |||
var log = require("mlogger"); | |||
var preprocess = require("./preprocess.js"); | |||
var sessions = {}; | |||
@@ -102,13 +103,14 @@ module.exports.prototype = { | |||
_end: function(str) { | |||
if (this.conf.debug) { | |||
var ms = (new Date().getTime() - this.startTime.getTime()); | |||
console.log( | |||
log.info( | |||
"Request:\t"+ | |||
ms+" millisecond(s)\t"+ | |||
(this.statusCode || 200)+"\t"+ | |||
this.req.url | |||
); | |||
} else { | |||
console.log(this.req.url); | |||
log.info("Request: "+this.req.url); | |||
} | |||
this.res.writeHead(this.statusCode, this.headers); | |||
@@ -142,8 +144,8 @@ module.exports.prototype = { | |||
}, | |||
fail: function(err) { | |||
console.log("Sending error to client:"); | |||
console.trace(err); | |||
log.info("Sending error to client:"); | |||
log.info(err); | |||
this.setHeader("Content-Type", "application/json"); | |||
@@ -1,6 +1,7 @@ | |||
var fs = require("fs"); | |||
var zlib = require("zlib"); | |||
var browserPrefix = require("browser-prefix"); | |||
var log = require("mlogger"); | |||
var minify = require("./minify.js"); | |||
var includeHtml = require("./includeHtml.js"); | |||
@@ -49,8 +50,8 @@ exports.load = function(endpoints, conf) { | |||
//Errors will usually be because an endpoint doesn't exist | |||
} catch (err) { | |||
if (err.code == "ENOENT") { | |||
console.log(err.toString()); | |||
if (err.code === "ENOENT" || err.code === "MODULE_NOT_FOUND") { | |||
log.error("File not found: "+conf.dir.web+"/"+ep.path); | |||
errs = true; | |||
} else { | |||
throw err; |
@@ -19,6 +19,7 @@ | |||
"browser-prefix": "^0.1.0", | |||
"formidable": "^1.0.17", | |||
"html-minifier": "^0.7.2", | |||
"mlogger": "^1.1.0", | |||
"pg": "^4.4.0", | |||
"scrypt": "^4.0.7", | |||
"uglify-js": "^2.4.24", |
@@ -18,7 +18,14 @@ try { | |||
function deleteFiles(dir) { | |||
fs.readdirSync(dir).forEach(function(f) { | |||
wrench.rmdirSyncRecursive(dir+"/"+f); | |||
if (f[0] === ".") | |||
return; | |||
try { | |||
wrench.rmdirSyncRecursive(dir+"/"+f); | |||
} catch (err) { | |||
//:) | |||
} | |||
}); | |||
} | |||
@@ -4,8 +4,9 @@ var fs = require("fs"); | |||
var domain = require("domain"); | |||
var zlib = require("zlib"); | |||
var wrench = require("wrench"); | |||
var loader = require("./lib/loader.js"); | |||
var pg = require("pg"); | |||
var log = require("mlogger"); | |||
var loader = require("./lib/loader.js"); | |||
var Context = require("./lib/context.js"); | |||
var conf = JSON.parse(fs.readFileSync("conf.json")); | |||
@@ -138,7 +139,7 @@ db.connect(function() { | |||
} | |||
server.listen(conf.port); | |||
console.log("Listening on port "+conf.port+"."); | |||
log.info("Listening on port "+conf.port+"."); | |||
purgeCollections(); | |||
}); | |||
@@ -163,7 +164,7 @@ function purgeCollections() { | |||
}); | |||
if (res.rowCount > 0) { | |||
console.log( | |||
log.info( | |||
"Deleted "+res.rowCount+" collections "+ | |||
"from over "+timeout+" ago." | |||
); |
@@ -1,9 +0,0 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8"> | |||
</head> | |||
<body> | |||
404, file not found. | |||
</body> | |||
</html> |
@@ -1,15 +1,27 @@ | |||
var fs = require("fs"); | |||
var zlib = require("zlib"); | |||
var log = require("mlogger"); | |||
var gzipped; | |||
var favicon = fs.readFileSync("favicon.ico"); | |||
var favicon; | |||
try { | |||
favicon = fs.readFileSync("favicon.ico"); | |||
} catch (err) { | |||
if (err.code === "ENOENT") | |||
log.notice("No favicon.ico found."); | |||
else | |||
throw err; | |||
} | |||
zlib.gzip(favicon, function(err, res) { | |||
gzipped = res; | |||
}); | |||
if (favicon !== undefined) { | |||
zlib.gzip(favicon, function(err, res) { | |||
gzipped = res; | |||
}); | |||
} | |||
module.exports = function(ctx) { | |||
if (favicon) { | |||
ctx.res.setHeader( | |||
"Cache-Control", |