main.route.js
3 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var env = process.env.NODE_ENV || 'development';
var responseMsg = require('../modules/helper/responseMsg.js');
var log = require('../modules/helper/log.js');
var constants = require('../modules/helper/constants.js');
var cfg = require('../config/config.js').get(env);
var load = require('express-load');
module.exports = function (app) {
app.all('/*', function (req, res,next) {
// console.log(req.params)
// console.log(req.query)
// console.log(req.url)
var splitPath = req._parsedUrl.pathname.split("/");
//0 = ip host
//1 = 'cmf'
//2 = 'v1'
var objectData = {
method:req.method,
req:req,
res:res,
next:next,
splitPath:splitPath,
pathname:req._parsedUrl.pathname
};
switch (splitPath[3]) {
case "customers":
if(splitPath[splitPath.length-1] == "membercards")
{
doMembercards(objectData);
}
else
{
objectData.modules = app.modules.customer;
doCustomers(objectData);
}
break;
case "vizcards":
doVizcard(objectData);
break;
default: next();
break;
}
});
function doVizcard(objectData)
{
console.log("Route : "+objectData.pathname+" => doVizcard");
objectData.next();
}
function doMembercards(objectData)
{
console.log("Route : "+objectData.pathname+" => doMembercards");
objectData.next();
}
function doCustomers(objectData)
{
console.log("Route : "+objectData.pathname+" => doCustomers");
// "/cmf/v1/customers/:customerId",
// "/cmf/v1/customers/:userType/:userData",
// "/cmf/v1/customers"
var doAction = function(){
if(objectData.method == constants.METHOD.GET)
objectData.modules.customerCtrl.customer(objectData.req,objectData.res,objectData.next);
else
objectData.modules.postCustomerCtrl.customer(objectData.req,objectData.res,objectData.next);
};
switch (objectData.splitPath.length) {
case 4:
doAction();
break;
case 5:
objectData.req.params = {
customerId:objectData.splitPath[4]
};
doAction();
break;
case 6:
objectData.req.params = {
userType:objectData.splitPath[4],
userData:objectData.splitPath[5],
};
doAction();
break;
default:
objectData.next();
break;
}
}
};