| @@ -5,7 +5,7 @@ | |||
| "main": "index.js", | |||
| "scripts": { | |||
| "test": "echo \"Error: no test specified\" && exit 1", | |||
| "start": "node index.js", | |||
| "start": "node server.js", | |||
| "setup": "node scripts/setup.js", | |||
| "reset": "node scripts/reset.js" | |||
| }, | |||
| @@ -1,6 +1,7 @@ | |||
| var http = require("http"); | |||
| var https = require("https"); | |||
| var fs = require("fs"); | |||
| var domain = require("domain"); | |||
| var loader = require("./lib/loader.js"); | |||
| var pg = require("pg"); | |||
| var Context = require("./lib/context.js"); | |||
| @@ -13,7 +14,7 @@ var endpoints = { | |||
| "/favicon.ico": "favicon.ico", | |||
| "/global.css": "global.css", | |||
| "/global.js": "global.js", | |||
| "/404": "404.html", | |||
| "/404": "404.node.js", | |||
| //Index files | |||
| "/": "index/index.node.js", | |||
| @@ -77,3 +78,12 @@ db.connect(function() { | |||
| console.log("Listening on port "+conf.port+"."); | |||
| }); | |||
| //We don't want to crash even if something throws an uncaught exception. | |||
| var d = domain.create(); | |||
| d.on("error", function(err) { | |||
| console.trace(err); | |||
| }); | |||
| process.on("uncaughtException", function(err) { | |||
| console.trace(err); | |||
| }); | |||
| @@ -0,0 +1,9 @@ | |||
| <!DOCTYPE html> | |||
| <html> | |||
| <head> | |||
| <meta charset="utf-8"> | |||
| </head> | |||
| <body> | |||
| 404, file not found. | |||
| </body> | |||
| </html> | |||
| @@ -0,0 +1,3 @@ | |||
| module.exports = function(ctx) { | |||
| ctx.end(ctx.view("404")); | |||
| } | |||
| @@ -1,9 +1,20 @@ | |||
| var fs = require("fs"); | |||
| module.exports = function(ctx) { | |||
| var id = ctx.req.url.split("?")[1] | |||
| .replace(/\..*/, ""); | |||
| var id; | |||
| try { | |||
| id = ctx.req.url.split("?")[1].replace(/\..*/, ""); | |||
| } catch (err) { | |||
| return ctx.end(ctx.view("404")); | |||
| } | |||
| var readStream = fs.createReadStream(ctx.conf.dir.imgs+"/"+id); | |||
| readStream.pipe(ctx.res); | |||
| readStream.on("error", function(err){ | |||
| if (err.code == "ENOENT") | |||
| ctx.end(ctx.view("404")); | |||
| else | |||
| ctx.end(err.toString()); | |||
| }); | |||
| } | |||
| @@ -1,6 +1,9 @@ | |||
| module.exports = function(ctx) { | |||
| var id = parseInt(ctx.req.url.split("?")[1]); | |||
| if (isNaN(id)) | |||
| return ctx.end(ctx.view("404")); | |||
| ctx.db.query( | |||
| "SELECT id, name, description, extension "+ | |||
| "FROM images "+ | |||