forked from net900621/thrush
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.js
85 lines (81 loc) · 2.19 KB
/
controller.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
var util = require('util');
var _controller = function(){
this.listenStack = [];
this.listenDate = {};
this.listenCount = 0;
this.cssLink = [];
}
_controller.prototype = {
render : function(url, data){
var _tmp = './www/tmp/' + Date.now().toString()
,_data = libFs.readFileSync('./www/view/' + url + '.html', "utf8");
libFs.writeFileSync(_tmp, tmp.etic(_data, data, this.cssLink), {'encoding' : 'utf8'});
this.res.writeHead(200, {"Content-Type": "text/html" });
this.res.end(libFs.readFileSync(_tmp, "utf8"), "utf8");
},
listen : function(cbk){
var _num = 0;
var data = {};
var php = this.listenDate;
var _php = php;
var self = this;
if (!self.listenCount ) {
cbk(self.listenDate);
};
for (i in php){
data[i] = './www/model' + php[i] + '.js';
var url = self.listenDate[i];
if (!libFs.existsSync(data[i])) {
libFs.writeFileSync(self.req.logUrl , '4041 ' + self.listenDate[i] + '\n', {'encoding' : 'utf8'});
self.listenDate[i] = 'false';
self.listenCount --;
}else{
(function(i, url){
require(data[i]).dbThis(function(err,dd){
self.listenDate[i] = dd;
self.listenCount --;
if (!self.listenCount ) {
var v = self.listenDate[i];
var _type = typeof(v);
if (_type != 'object') {
libFs.writeFileSync(self.req.logUrl , '4042 ' + url + '\n', {'encoding' : 'utf8'});
}else{
libFs.writeFileSync(self.req.logUrl , '200 ' + url + '\n', {'encoding' : 'utf8'});
}
cbk(self.listenDate);
};
},self);
})(i, url);
}
}
},
setData : function(data){
_controller.call(this);
for (i in data){
this.listenStack.push(data[i]);
this.listenCount ++;
}
this.listenDate = data;
},
ajaxTo : function(data){
var self = this;
this.setData(data);
this.listen(function(data){
data = JSON.stringify(data);
self.res.writeHead(200, {"Content-Type": "application/json" });
self.res.end(data, "utf8");
});
}
}
exports.__create = function(module, conf){
// var _path = '', _pathName = '';
util.inherits(module, _controller);
if (conf) {
for (var k in conf)
module.prototype[k] = conf[k];
}
return function(modName, appPath){
var modObj = new module;
return modObj;
}
}