From 0b0882e63d1add6e1bec4e0672cfd8e6445185cc Mon Sep 17 00:00:00 2001 From: jomo Date: Mon, 20 Apr 2015 22:19:57 +0200 Subject: [PATCH] use new response module for index --- lib/response.js | 7 +++++-- lib/routes/index.js | 11 +++++------ lib/server.js | 4 +++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/response.js b/lib/response.js index 4cb3f13..0d780ad 100644 --- a/lib/response.js +++ b/lib/response.js @@ -16,7 +16,7 @@ var human_status = { // +request+ a http.IncomingMessage // +response+ a http.ServerResponse // +result+ an object with: -// * status: see human_status, required +// * status: see human_status, required for images // * redirect: redirect URL // * body: file or message, required unless redirect is present or status is < 0 // * type: a valid Content-Type for the body, defaults to "text/plain" @@ -41,11 +41,14 @@ module.exports = function(request, response, result) { "Content-Type": result.type || "text/plain", "Cache-Control": "max-age=" + config.browser_cache_time + ", public", "Response-Time": Date.now() - request.start, - "X-Storage-Type": human_status[result.status], "X-Request-ID": request.id, "Access-Control-Allow-Origin": "*" }; + if (result.status) { + headers["X-Storage-Type"] = human_status[result.status]; + } + if (result.err) { logging.error(result.err); } diff --git a/lib/routes/index.js b/lib/routes/index.js index 3a2498a..7ffbcb2 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -3,17 +3,16 @@ var path = require("path"); var jade = require("jade"); // compile jade -var index = jade.compileFile(path.join(__dirname, "../views/index.jade")); +var index = jade.compileFile(path.join(__dirname, "..", "views", "index.jade")); -module.exports = function(req, res) { +module.exports = function(req, callback) { var html = index({ title: "Crafatar", domain: "https://" + req.headers.host, config: config }); - res.writeHead(200, { - "Content-Length": Buffer.byteLength(html, "UTF-8"), - "Content-Type": "text/html; charset=utf-8" + callback({ + body: html, + type: "text/html; charset=utf-8" }); - res.end(html); }; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 605b338..66a4d12 100644 --- a/lib/server.js +++ b/lib/server.js @@ -70,7 +70,9 @@ function requestHandler(req, res) { try { switch (local_path) { case "": - routes.index(req, res); + routes.index(req, function(result) { + response(req, res, result); + }); break; case "avatars": routes.avatars(req, function(result) {