Mikael's blog

A developers sixth time trying to maintain a blog

Source Code - Root / index.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*****************************************
 *   Index - Blog startup script
 *****************************************
 *   Author:  mikael.lofjard@gmail.com
 *   Website: http://lofjard.se
 *   License: MIT License
 ****************************************/
  
var server = require('./server').Server;
var router = require('./router').Router;
var masterController = require('./masterController').MasterController;
var viewManager = require('./viewManager').ViewManager;
var environmentManager = require('./environmentManager').EnvironmentManager;
var databaseManager = require('./databaseManager').DatabaseManager;
var searchManager = require('./searchManager').SearchManager;
var cacheManager = require('./cacheManager').CacheManager;
var secrets = require('./secrets/secrets').Secrets;
  
// ---- Routing configuration ---- //
var routes = {};
// blog routes
routes['/'] = masterController.page;
routes['/atomfeed'] = masterController.atomFeed;
routes['/post/{id}'] = masterController.getPost;
routes['/page/{key}'] = masterController.page;
routes['/archive'] = masterController.archive;
routes['/archive/{year}'] = masterController.archive;
routes['/tags'] = masterController.tags;
routes['/tag/{tag}'] = masterController.tag;
routes['/about'] = masterController.about;
routes['/source'] = masterController.source;
routes['/source/dir/{dir}'] = masterController.sourceDir;
routes['/source/file/{file}'] = masterController.sourceFile;
routes['/comment'] = masterController.comment;
routes['/search'] = masterController.searchIndex;
routes['/search/{term}'] = masterController.search;
routes['/admin'] = masterController.admin;
routes['/admin/get/{id}'] = masterController.getPostAsJson;
routes['/admin/submit'] = masterController.submitPost;
routes['/admin/upload'] = masterController.upload;
  
// ---- Bundling configuration ---- //
var options = {
  bundleConfig: {
    scripts: {
      path: './content/scripts',
      outputPath: '/data/www/blog/scripts',
      minimize: true,
      compress: true
    },
    css: {
      path: './content/css',
      outputPath: '/data/www/blog/css',
      mainFile: 'lofjard.less',
      minimize: true,
      compress: true
    }
  },
  uploadPath: '/data/www/blog/img/upload'
};
  
// ---- View template configuration ---- //
var templatePath = './views';
  
// ---- Google Analytics tracking configuration ---- //
var trackingCodePath = './trackingCode.inc';
  
// ---- CouchDB configuration ---- //
var couchDBConfig = {
  host: 'blog-db',
  port: 5984,
  database: 'blog'
};
  
environmentManager.init(trackingCodePath);
  
// ---- Web Server configuration ---- //
var serverConfig = {
  httpPort: environmentManager.httpPort(),
};
  
// initialize modules and start web server
var db = databaseManager.init(couchDBConfig);
searchManager.init(db);
cacheManager.init();
viewManager.init(templatePath);
masterController.init(db, options);
router.init(routes);
server.init(serverConfig);
server.start(router.route);