app.js 798B

123456789101112131415161718192021222324252627282930313233343536
  1. const path = require('path');
  2. const express = require('express');
  3. const tinylr = require('../..');
  4. const debug = require('debug')('tinylr:server');
  5. const gaze = require('gaze');
  6. process.env.DEBUG = process.env.DEBUG || 'tinylr*';
  7. var app = module.exports = express();
  8. function logger (fmt) {
  9. fmt = fmt || '%s - %s';
  10. return function logger (req, res, next) {
  11. debug(fmt, req.method, req.url);
  12. next();
  13. };
  14. }
  15. (function watch (em) {
  16. em = em || new (require('events').EventEmitter)();
  17. gaze(path.join(__dirname, 'styles/site.css'), function () {
  18. this.on('changed', function (filepath) {
  19. tinylr.changed(filepath);
  20. });
  21. });
  22. return watch;
  23. })();
  24. app
  25. .use(logger())
  26. .use('/', express.static(path.join(__dirname)))
  27. .use(tinylr.middleware({ app: app }));