-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (59 loc) · 2.32 KB
/
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
'use strict';
global.__root = __dirname;
var kraken = require('kraken-js'),
express = require('express'),
app = {},
fs = require('fs'),
path = require('path');
app.configure = function configure(server, next) {
// Async method run on startup.
next(null);
};
app.requestStart = function requestStart(server) {
// Run before most express middleware has been registered.
};
app.requestBeforeRoute = function requestBeforeRoute(server) {
// Run before any routes have been added.
//get custom controller if any
var customControllersDir = path.resolve(__dirname+'/controllers/themes/');
server.customControllers = [];
var themes = fs.readdirSync(customControllersDir);
themes.forEach(function(theme){
server.customControllers[theme] = [];
var customControllersDirByTheme = fs.readdirSync(customControllersDir+"/"+theme);
customControllersDirByTheme.forEach(function(customController){
//remove the extension
customController = customController.replace(/\.[^/.]+$/, "");
var customControllerPath = customControllersDir+"/"+theme+"/"+customController;
server.customControllers[theme][customController] = require(customControllerPath)(server);
});
});
server.customConfig = require('./config/customConfig.json');
var scrappers = require('./lib/scrappers.js');
server.customConfig.scrappers = scrappers.getScrappersConfig();
server.use(express.methodOverride());
};
app.requestAfterRoute = function requestAfterRoute(server) {
// Run after all routes have been added.
//if route is not found redirect to index controller with current route as a view to display
var errorFunc = function(){
return function (req, res, next) {
var i = 0;
while (i < server.routes.get.length && server.routes.get[i].path !== "/"){
i++;
}
req.themedController = req._parsedUrl.path.substr(1,req._parsedUrl.path.length);
server.routes.get[i].callbacks[0](req, res, next);
}
};
server.use(errorFunc());
};
if (require.main === module) {
kraken.create(app).listen(function (err) {
if (err) {
console.error(err.stack);
}
require('./lib/dustjs-helpers.js');
});
}
module.exports = app;