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

"session_timeout": 1800000, "session_timeout": 1800000,
"dir": { "dir": {
"imgs": "imgs", "imgs": "imgs",
"web": "web
"web": "web"
}, },
"debug": false, "debug": false,
"max_runs": 9999, "max_runs": 9999,

+ 6
- 4
lib/context.js View File

var crypto = require("crypto"); var crypto = require("crypto");
var zlib = require("zlib"); var zlib = require("zlib");
var fs = require("fs"); var fs = require("fs");
var log = require("mlogger");
var preprocess = require("./preprocess.js"); var preprocess = require("./preprocess.js");


var sessions = {}; var sessions = {};
_end: function(str) { _end: function(str) {
if (this.conf.debug) { if (this.conf.debug) {
var ms = (new Date().getTime() - this.startTime.getTime()); var ms = (new Date().getTime() - this.startTime.getTime());
console.log(
log.info(
"Request:\t"+
ms+" millisecond(s)\t"+ ms+" millisecond(s)\t"+
(this.statusCode || 200)+"\t"+ (this.statusCode || 200)+"\t"+
this.req.url this.req.url
); );
} else { } else {
console.log(this.req.url);
log.info("Request: "+this.req.url);
} }


this.res.writeHead(this.statusCode, this.headers); this.res.writeHead(this.statusCode, this.headers);
}, },


fail: function(err) { 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"); this.setHeader("Content-Type", "application/json");



+ 3
- 2
lib/loader.js View File

var fs = require("fs"); var fs = require("fs");
var zlib = require("zlib"); var zlib = require("zlib");
var browserPrefix = require("browser-prefix"); var browserPrefix = require("browser-prefix");
var log = require("mlogger");
var minify = require("./minify.js"); var minify = require("./minify.js");
var includeHtml = require("./includeHtml.js"); var includeHtml = require("./includeHtml.js");




//Errors will usually be because an endpoint doesn't exist //Errors will usually be because an endpoint doesn't exist
} catch (err) { } 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; errs = true;
} else { } else {
throw err; throw err;

+ 1
- 0
package.json View File

"browser-prefix": "^0.1.0", "browser-prefix": "^0.1.0",
"formidable": "^1.0.17", "formidable": "^1.0.17",
"html-minifier": "^0.7.2", "html-minifier": "^0.7.2",
"mlogger": "^1.1.0",
"pg": "^4.4.0", "pg": "^4.4.0",
"scrypt": "^4.0.7", "scrypt": "^4.0.7",
"uglify-js": "^2.4.24", "uglify-js": "^2.4.24",

+ 8
- 1
scripts/reset.js View File



function deleteFiles(dir) { function deleteFiles(dir) {
fs.readdirSync(dir).forEach(function(f) { 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

var domain = require("domain"); var domain = require("domain");
var zlib = require("zlib"); var zlib = require("zlib");
var wrench = require("wrench"); var wrench = require("wrench");
var loader = require("./lib/loader.js");
var pg = require("pg"); var pg = require("pg");
var log = require("mlogger");
var loader = require("./lib/loader.js");
var Context = require("./lib/context.js"); var Context = require("./lib/context.js");


var conf = JSON.parse(fs.readFileSync("conf.json")); var conf = JSON.parse(fs.readFileSync("conf.json"));
} }
server.listen(conf.port); server.listen(conf.port);


console.log("Listening on port "+conf.port+".");
log.info("Listening on port "+conf.port+".");


purgeCollections(); purgeCollections();
}); });
}); });


if (res.rowCount > 0) { if (res.rowCount > 0) {
console.log(
log.info(
"Deleted "+res.rowCount+" collections "+ "Deleted "+res.rowCount+" collections "+
"from over "+timeout+" ago." "from over "+timeout+" ago."
); );

+ 0
- 9
web/404.html View File

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

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

var fs = require("fs"); var fs = require("fs");
var zlib = require("zlib"); var zlib = require("zlib");
var log = require("mlogger");


var gzipped; 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) { module.exports = function(ctx) {

if (favicon) { if (favicon) {
ctx.res.setHeader( ctx.res.setHeader(
"Cache-Control", "Cache-Control",

Loading…
Cancel
Save