Browse Source

moved to mlogger for logging instead of directly calling console.log

master
mort 8 years ago
parent
commit
322049eedf
8 changed files with 39 additions and 24 deletions
  1. 1
    1
      conf.json.example
  2. 6
    4
      lib/context.js
  3. 3
    2
      lib/loader.js
  4. 1
    0
      package.json
  5. 8
    1
      scripts/reset.js
  6. 4
    3
      server.js
  7. 0
    9
      web/404.html
  8. 16
    4
      web/favicon.node.js

+ 1
- 1
conf.json.example View File

@@ -20,7 +20,7 @@
"session_timeout": 1800000,
"dir": {
"imgs": "imgs",
"web": "web
"web": "web"
},
"debug": false,
"max_runs": 9999,

+ 6
- 4
lib/context.js View File

@@ -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");


+ 3
- 2
lib/loader.js View File

@@ -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;

+ 1
- 0
package.json View File

@@ -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",

+ 8
- 1
scripts/reset.js View File

@@ -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
- 3
server.js View File

@@ -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."
);

+ 0
- 9
web/404.html View File

@@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
404, file not found.
</body>
</html>

+ 16
- 4
web/favicon.node.js View File

@@ -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",

Loading…
Cancel
Save