-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFexPress.js
61 lines (61 loc) · 1.46 KB
/
FexPress.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
const req = {
query: {
test: "testing worked"
}
}
const res = {
redirect(url) {
console.log("FexPress: (.redirect) redirected to '" + url + "'");
},
end(str) {
console.log("FexPress: (.end) ended '" + str + "'");
},
write(str) {
console.log("FexPress: (.write) wrote '" + str + "'");
},
send(str) {
console.log("FexPress: (.send) recived '" + str + "'");
},
json(str) {
console.log("FexPress: (.json) recived JSON '" + JSON.stringify(str) + "'");
},
}
let gets = [];
const clone = function() {
console.log("FexPress: clone made");
return {
use(instance) {
console.log("FexPress: app has USED " + JSON.stringify(instance));
},
get(endpoint, callback) {
console.log("FexPress: GET request saved.");
gets.push({ endpoint, callback });
},
FEXHandle(endpoint) {
for (var get of gets) {
if (get.endpoint == endpoint) {
get.callback(req, res);
}
}
},
listen(port) {
console.log("FexPress: Is not listening on " + port);
console.log("FexPress: Testing all handlers now!");
for (var ep of gets) {
console.log("Handling " + ep.endpoint + " below:")
this.FEXHandle(ep.endpoint);
}
}
}
}
clone.static = (dir) => {
console.log("FexPress: STATIC created for '" + dir + "'");
return { dirname: dir };
}
clone.fakes = {
res: () => { },
req: () => { }
};
clone.fakes.res = res;
clone.fakes.req = req;
module.exports = clone;