]> git.r.bdr.sh - rbdr/lgtm/blobdiff - index.js
Fetch random record in record_fetcher
[rbdr/lgtm] / index.js
index 46d4049aa9245640d3199893601a4fea0d93e533..cc5c3b9685c936539abb988627ce9396e4cd509c 100644 (file)
--- a/index.js
+++ b/index.js
@@ -3,15 +3,28 @@
 const Config = require('./config/config');
 const Koa = require('koa');
 const KoaStatic = require('koa-static');
+const Nunjucks = require('nunjucks');
+const RecordFetcher = require('./lib/record_fetcher');
 
 const internals = {};
 
 internals.run = () => {
 
+  Nunjucks.configure(Config.templateDirectory);
+
   internals.app = Koa();
 
   internals.app.use(KoaStatic(Config.staticDirectory));
 
+  const recordFetcher = new RecordFetcher();
+  internals.app.use(function * () {
+
+    const record = yield recordFetcher.fetch();
+    const parsedTemplate = Nunjucks.render('index.html.njk', record);
+
+    this.body = parsedTemplate;
+  });
+
   console.log('        .');
   console.log('       /');
   console.log('    +-----+');