aboutsummaryrefslogtreecommitdiff
path: root/index.js
blob: cc5c3b9685c936539abb988627ce9396e4cd509c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';

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('    +-----+');
  console.log(`    | o o |  - Listening Gladly, Try Me: ${Config.port}`);
  console.log('    +-----+');
  console.log('  +---------+');
  console.log(' /|    [][] |\\');
  console.log(' ||         | |');
  console.log(' ||         |  \\c');
  console.log(' ^+---------+');
  console.log('      (.) ');
  internals.app.listen(Config.port);
};

internals.run();