index.js 746 B

12345678910111213141516171819202122232425262728293031323334
  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. // pre-compile the index page
  9. function compile() {
  10. logging.log("Compiling index page");
  11. str = read(path.join(__dirname, "..", "views", "index.html.ejs"), "utf-8");
  12. index = ejs.compile(str);
  13. }
  14. compile();
  15. // GET index request
  16. module.exports = function(req, callback) {
  17. if (config.server.debug_enabled) {
  18. // allow changes without reloading
  19. compile();
  20. }
  21. var html = index({
  22. title: "Crafatar",
  23. domain: "https://" + req.headers.host,
  24. config: config
  25. });
  26. callback({
  27. body: html,
  28. type: "text/html; charset=utf-8"
  29. });
  30. };