index.js 695 B

1234567891011121314151617181920212223242526272829303132
  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. module.exports = function(req, callback) {
  15. if (config.server.debug_enabled) {
  16. // allow changes without reloading
  17. compile();
  18. }
  19. var html = index({
  20. title: "Crafatar",
  21. domain: "https://" + req.headers.host,
  22. config: config
  23. });
  24. callback({
  25. body: html,
  26. type: "text/html; charset=utf-8"
  27. });
  28. };