index.js 716 B

123456789101112131415161718192021222324252627282930313233
  1. var logging = require("../logging");
  2. var config = require("../../config");
  3. var path = require("path");
  4. var read = require("fs").readFileSync;
  5. var ejs = require("ejs");
  6. var str;
  7. var index;
  8. function compile() {
  9. logging.log("Compiling index page");
  10. str = read(path.join(__dirname, "..", "views", "index.html.ejs"), "utf-8");
  11. index = ejs.compile(str);
  12. }
  13. compile();
  14. // GET index request
  15. module.exports = function(req, callback) {
  16. if (config.server.debug_enabled) {
  17. // allow changes without reloading
  18. compile();
  19. }
  20. var html = index({
  21. title: "Crafatar",
  22. domain: "https://" + req.headers.host,
  23. config: config
  24. });
  25. callback({
  26. body: html,
  27. type: "text/html; charset=utf-8"
  28. });
  29. };