From ead516a9d74f346c4556c7eaab7014f95486f29e Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 28 Nov 2016 02:28:17 -0600 Subject: LGTM-2 Read from database Squashed commit of the following: commit a2a2b553f69a66f1825347abde4f0028773bdbdb Author: Ben Beltran Date: Mon Nov 28 02:27:19 2016 -0600 Fetch random record in record_fetcher commit 6b98202fc8ea9c5811134cad592f11b6b89d008a Author: Ben Beltran Date: Mon Nov 28 02:27:08 2016 -0600 Add some instructions to the readme commit f5efb2b5de23844e6317a6f636abb75955e60c40 Author: Ben Beltran Date: Mon Nov 28 02:26:57 2016 -0600 Add DB setup script commit d6d8813ef55bb1297089c9dbb87a9ab86e6c5ba2 Author: Ben Beltran Date: Mon Nov 28 02:26:34 2016 -0600 Add dotenv to the configs commit 649f66982d2152d36a782577043505835f235987 Author: Ben Beltran Date: Mon Nov 28 01:29:49 2016 -0600 Use a template instead of static html index --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'index.js') diff --git a/index.js b/index.js index 46d4049..cc5c3b9 100644 --- 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(' +-----+'); -- cgit