-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroute.js
More file actions
52 lines (47 loc) · 1.32 KB
/
route.js
File metadata and controls
52 lines (47 loc) · 1.32 KB
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
/**
* @description
* WALNUT NodeJS MVC framework
*
* Copy right 2011, xukai.ken@gmail.com (XU Kai)
* Date 2011.11.10
*/
var path = require('path');
var parseURL = require('url').parse;
var fileSystem = require('fs');
var routeInformation = [];
/**
* @description Request the action information.
* @param {string} urlString The URL information.
* @param {function} callback
*/
exports.requestAction = function(callback, urlString, DEFAULT_URL) {
fileSystem.readFile(Walnut.config.routeConfiguration, function (error, data) {
routeInformation = JSON.parse(data);
this.routeInformation = routeInformation;
if (urlString == '/')
urlString = Walnut.config.DEFAULT_URL;
var controller = parseURL(urlString).pathname.slice(1);
var actionInfo = (routeInformation[controller])?(routeInformation[controller]):null;
if (actionInfo) {
if (typeof(callback) == 'function')
callback(controller, actionInfo);
} else {
callback(urlString);
}
});
};
/**
* @description Execute the action.
* @param {object} request
* @param {object} response
*/
exports.executeAction = function(request, response) {
var renderEngine = Walnut.config.viewRenderEngine;
var self = this;
path.exists(renderEngine + '.js', function(exists){
if (exists) {
require(renderEngine);
self.execute(request, response);
}
});
}