-
Notifications
You must be signed in to change notification settings - Fork 0
/
moDOOle.js
50 lines (39 loc) · 1.04 KB
/
moDOOle.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
var http = require('http');
var url = require('url');
var fs = require('fs');
const doo = require('modoole');
var viewFolder
var reqVar;
var resVar;
exports.log = function (content = "I'm working!") {
console.log('modoole: ' + content)
};
exports.web = function (port = 5000, code = function code(){}){
http.createServer(function (req, res) {
reqVar = req;
resVar = res;
code();
}).listen(port);
};
exports.setViewFolder = function (folderName = '') {
viewFolder = folderName;
};
exports.route = function (fileName, routeName = ''){
req = reqVar;
res = resVar;
var q = url.parse(req.url, true);
routeName = '/' + routeName;
if(routeName == q.pathname){
doo.renderHTML(fileName)
}
};
exports.renderHTML = function (fileName){
req = reqVar;
res = resVar;
fileName = viewFolder + '/' + fileName;
fs.readFile(fileName, function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
});
};