forked from ufologist/RAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrap.plugin.xinglie.js
869 lines (739 loc) · 26.1 KB
/
rap.plugin.xinglie.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
/*! rap.plugin May.30th 2014 by 行列 */
(function () {
var node = null;
var blackList = [];
var whiteList = ["/api/dspfilter/zonesizes", "/api/dspfilter/distypes", "/api/dspfilter/screens", "/api/dspfilter/sitetypes", "/api/dspfilter/pagelist", "/api/dspfilter/urls", "/api/dspsettle/account/balance", "/api/dspsettle/account/list", "/api/log", "/api/dspsettle/account/anotice"];
var ROOT = 'DOMAIN';
// [DEBUG]
// ROOT = 'etaoux-bj.taobao.ali.com:8080';
var LOST = "LOST";
var PREFIX = "/mockjs/";
var EMPTY_ARRAY = "EMPTY_ARRAY";
var TYPE_NOT_EQUAL = "TYPE_NOT_EQUAL";
/**
* mode value range: 0-disabled 1-intercept all requests 2-black list
* strategy 3-white list strategy
*/
var mode = 3;
var modeList = [0, 1, 2, 3];
var projectId = 0;
// console handler
if (typeof window.console === 'undefined') {
window.console = {
log: function () {
},
warn: function () {
},
info: function () {
},
dir: function () {
}
};
}
if (!node) {
var nodes = document.getElementsByTagName('script');
node = nodes[nodes.length - 1];
}
var ms = node.src.match(/(?:\?|&)projectId=([^&]+)(?:&|$)/);
if (ms) {
projectId = ms[1];
}
var modePattern = node.src.match(/(?:\?|&)mode=([^&]+)(?:&|$)/);
if (modePattern) {
mode = +modePattern[1];
if (!(mode in modeList)) {
mode = 1;
}
}
var rootPattern = node.src.match(/(?:\?|&)root=([^&]+)(?:&|$)/);
if (rootPattern) {
ROOT = rootPattern[1];
}
var enable = true;
console.log('Current RAP work mode:', mode, "(0-disabled, 1-intercept all requests, 2-black list, 3-white list)");
var ens = node.src.match(/(?:\?|&)enable=([^&]+)(?:&|$)/);
if (ens) {
enable = ens[1] == 'true';
}
/*function wrapJQuery(jQuery) {
if (jQuery._rap_wrapped) {
return;
}
jQuery._rap_wrapped = true;
var ajax = jQuery.ajax;
jQuery.ajax = function() {
var oOptions = arguments[0];
var url = oOptions.url;
if (route(url) && projectId) {
rapUrlConverterJQuery(oOptions);
var oldSuccess1 = oOptions.success;
oldSuccess1 && (oOptions.success = function(data) {
if (PREFIX == '/mockjs/') {
data = Mock.mock(data);
console.log('请求' + url + '返回的Mock数据:');
console.dir(data);
}
oldSuccess1.apply(this, arguments);
});
var oldComplete = oOptions.complete;
oldComplete && (oOptions.complete = function(data) {
if (PREFIX == '/mockjs/') {
data = Mock.mock(data);
console.log('请求' + url + '返回的Mock数据:');
console.dir(data);
}
oldComplete.apply(this, arguments);
});
} else if (isInWhiteList(url) && !oOptions.RAP_NOT_TRACK) {
var checkerOptions = {
url: oOptions.url
};
rapUrlConverterJQuery(checkerOptions);
checkerOptions.RAP_NOT_TRACK = true;
checkerOptions.success = checkerHandler;
// real data checking
var oldSuccess2 = oOptions.success;
oOptions.success = function() {
var realData = arguments[0];
checkerOptions.context = {
data: realData,
url: oOptions.url
};
// perform real data check
ajax.apply(jQuery, [checkerOptions]);
oldSuccess2.apply(this, arguments);
};
}
ajax.apply(this, arguments);
};
}
window.wrapJQueryForRAP = wrapJQuery;*/
// ************************************************************************************************
var guid = +new Date();
var JSONP = function (url, callback) {
var me = this;
var script = document.createElement('script');
var key = 'jsonp' + guid++;
var success;
window[key] = function (data) {
callback(data);
delete window[key];
success = true;
};
script.onload = script.onreadystatechange = script.onerror = function () {
setTimeout(function () {
script.parentNode.removeChild(script);
if (!success) {
callback('script error');
delete window[key];
}
}, 0);
};
script.src = url + '&_c=' + key;
document.body.appendChild(script);
};
var isFunction = function (f) {
return Object.prototype.toString.call(f) == '[object Function]';
};
var parseURLParamsArray = function (url) {
var q = url ? url.indexOf("?") : -1;
if (q == -1) return [];
var search = url.substr(q + 1);
var h = search.lastIndexOf("#");
if (h != -1) search = search.substr(0, h);
if (!search) return [];
return parseURLEncodedTextArray(search);
};
var parseURLEncodedTextArray = function (text) {
var maxValueLength = 25000;
var params = [];
// Unescape '+' characters that are used to encode a space.
// See section 2.2.in RFC 3986: http://www.ietf.org/rfc/rfc3986.txt
text = text.replace(/\+/g, " ");
var args = text.split("&");
for (var i = 0; i < args.length; ++i) {
try {
var parts = args[i].split("=");
if (parts.length == 2) {
if (parts[1].length > maxValueLength) parts[1] = this.$STR("LargeData");
params.push({
name: decodeURIComponent(parts[0]),
value: [decodeURIComponent(parts[1])]
});
} else params.push({
name: decodeURIComponent(parts[0]),
value: [""]
});
} catch (e) {
console.log(e);
}
}
params.sort(function (a, b) {
return a.name <= b.name ? -1 : 1;
});
return params;
}
// ************************************************************************************************
// XMLHttpRequestWrapper
var XMLHttpRequestWrapper = function (activeXObject) {
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// XMLHttpRequestWrapper internal variables
var xhrRequest = typeof activeXObject != "undefined" ? activeXObject : new _XMLHttpRequest(),
self = this,
reqType,
reqUrl,
reqStartTS;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// XMLHttpRequestWrapper internal methods
var updateSelfPropertiesIgnore = {
abort: 1,
channel: 1,
getAllResponseHeaders: 1,
getInterface: 1,
getResponseHeader: 1,
mozBackgroundRequest: 1,
multipart: 1,
onreadystatechange: 1,
open: 1,
send: 1,
setRequestHeader: 1
};
var updateSelfProperties = function () {
if (supportsXHRIterator) {
for (var propName in xhrRequest) {
if (propName in updateSelfPropertiesIgnore) continue;
try {
var propValue = xhrRequest[propName];
if (propValue && !isFunction(propValue)) self[propName] = propValue;
} catch (E) {
//console.log(propName, E.message);
}
}
} else {
// will fail to read these xhrRequest properties if the request is not completed
if (xhrRequest.readyState == 4) {
self.status = xhrRequest.status;
self.statusText = xhrRequest.statusText;
self.responseText = xhrRequest.responseText;
self.responseXML = xhrRequest.responseXML;
}
}
};
var updateXHRPropertiesIgnore = {
channel: 1,
onreadystatechange: 1,
readyState: 1,
responseBody: 1,
responseText: 1,
responseXML: 1,
status: 1,
statusText: 1,
upload: 1
};
var updateXHRProperties = function () {
for (var propName in self) {
if (propName in updateXHRPropertiesIgnore) continue;
try {
var propValue = self[propName];
if (propValue && !xhrRequest[propName]) {
xhrRequest[propName] = propValue;
}
} catch (E) {
//console.log(propName, E.message);
}
}
};
var handleStateChange = function () {
//Firebug.Console.log(["onreadystatechange", xhrRequest.readyState, xhrRequest.readyState == 4 && xhrRequest.status]);
self.readyState = xhrRequest.readyState;
if (xhrRequest.readyState == 4) {
updateSelfProperties();
xhrRequest.onreadystatechange = function () {
};
}
//Firebug.Console.log(spy.url + ": " + xhrRequest.readyState);
self.onreadystatechange();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// XMLHttpRequestWrapper public properties and handlers
this.readyState = 0;
this.onreadystatechange = function () {
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// XMLHttpRequestWrapper public methods
this.open = function (method, url, async, user, password) {
//Firebug.Console.log("xhrRequest open");
updateSelfProperties();
if (route(url) && projectId) {
url = convertUrlToRelative(url);
url = "http://" + ROOT + PREFIX + projectId + url;
console.log(url);
this.$useJSONP = true;
this.$url = url;
return;
}
try {
// xhrRequest.open.apply may not be available in IE
if (supportsApply) xhrRequest.open.apply(xhrRequest, arguments);
else xhrRequest.open(method, url, async, user, password);
} catch (e) {
}
xhrRequest.onreadystatechange = handleStateChange;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
this.send = function (data) {
if (this.$useJSONP) {
var me = this;
JSONP(me.$url, function (data) {
console.log(data);
if (data !== 'script error') {
data = JSON.stringify(Mock.mock(data));
}
me.status = 200;
me.readyState = 4;
me.responseText = data;
me.responseXML = data;
me.onreadystatechange();
});
return;
}
//Firebug.Console.log("xhrRequest send");
updateXHRProperties();
try {
xhrRequest.send(data);
} catch (e) {
// TODO: xxxpedro XHR throws or not?
//throw e;
} finally {
updateSelfProperties();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
this.setRequestHeader = function (header, value) {
if (this.$useJSONP) return;
return xhrRequest.setRequestHeader(header, value);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
this.abort = function () {
if (this.$useJSONP) return;
xhrRequest.abort();
updateSelfProperties();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
this.getResponseHeader = function (header) {
return xhrRequest.getResponseHeader(header);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
this.getAllResponseHeaders = function () {
return xhrRequest.getAllResponseHeaders();
};
/**/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Clone XHR object
// xhrRequest.open.apply not available in IE and will throw an error in
// IE6 by simply reading xhrRequest.open so we must sniff it
var supportsApply = !isIE6 && xhrRequest && xhrRequest.open && typeof xhrRequest.open.apply != "undefined";
var numberOfXHRProperties = 0;
for (var propName in xhrRequest) {
numberOfXHRProperties++;
if (propName in updateSelfPropertiesIgnore) continue;
try {
var propValue = xhrRequest[propName];
if (isFunction(propValue)) {
if (typeof self[propName] == "undefined") {
this[propName] = (function (name, xhr) {
return supportsApply ?
// if the browser supports apply
function () {
return xhr[name].apply(xhr, arguments);
} : function (a, b, c, d, e) {
return xhr[name](a, b, c, d, e);
};
})(propName, xhrRequest);
}
} else this[propName] = propValue;
} catch (E) {
//console.log(propName, E.message);
}
}
// IE6 does not support for (var prop in XHR)
var supportsXHRIterator = numberOfXHRProperties > 0;
/**/
return this;
};
// ************************************************************************************************
// ActiveXObject Wrapper (IE6 only)
var _ActiveXObject;
var isIE6 = /msie 6/i.test(navigator.appVersion);
if (isIE6) {
_ActiveXObject = window.ActiveXObject;
var xhrObjects = " MSXML2.XMLHTTP.5.0 MSXML2.XMLHTTP.4.0 MSXML2.XMLHTTP.3.0 MSXML2.XMLHTTP Microsoft.XMLHTTP ";
window.ActiveXObject = function (name) {
var error = null;
try {
var activeXObject = new _ActiveXObject(name);
} catch (e) {
error = e;
} finally {
if (!error) {
if (xhrObjects.indexOf(" " + name + " ") != -1) return new XMLHttpRequestWrapper(activeXObject);
else return activeXObject;
} else throw error.message;
}
};
}
// ************************************************************************************************
// Register the XMLHttpRequestWrapper for non-IE6 browsers
if (!isIE6) {
var _XMLHttpRequest = XMLHttpRequest;
window.XMLHttpRequest = function () {
return new XMLHttpRequestWrapper();
};
}
// ************************************************************************************************
if (enable) {
/**
* jQuery override
*/
/*if (window.jQuery) {
wrapJQuery(window.jQuery);
}*/
/**
* kissy override
*/
/*if (window.KISSY) {
KISSY.oldUse = KISSY.use;
KISSY.oldAdd = KISSY.add;
KISSY.add('rap_io', function(S, IO) {
var oldIO = IO;
var key;
var fn = KISSY.io = KISSY.IO = KISSY.ajax = function(options) {
var oOptions, url;
if (arguments[0]) {
oOptions = arguments[0];
url = oOptions.url;
if (route(url) && !oOptions.RAP_NOT_TRACK) {
rapUrlConverterKissy(oOptions);
var oldSuccess1 = oOptions.success;
oldSuccess1 && (oOptions.success = function(data) {
if (PREFIX == '/mockjs/') {
data = Mock.mock(data);
console.log('请求' + url + '返回的Mock数据:');
console.dir(data);
}
oldSuccess1.apply(this, arguments);
});
var oldComplete = oOptions.complete;
oldComplete && (oOptions.complete = function(data) {
if (PREFIX == '/mockjs/') {
data = Mock.mock(data);
console.log('请求' + url + '返回的Mock数据:');
console.dir(data);
}
oldComplete.apply(this, arguments);
});
} else if (isInWhiteList(url) && !oOptions.RAP_NOT_TRACK) {
var checkerOptions = {
url: oOptions.url
};
rapUrlConverterKissy(checkerOptions);
checkerOptions.RAP_NOT_TRACK = true;
checkerOptions.success = checkerHandler;
// real data checking
var oldSuccess2 = oOptions.success;
oOptions.success = function() {
var realData = arguments[0];
checkerOptions.context = {
data: realData,
url: oOptions.url
};
// perform real data check
IO(checkerOptions);
oldSuccess2.apply(this, arguments);
};
}
}
IO.apply(this, arguments);
};
for (key in oldIO) {
if (oldIO.hasOwnProperty(key)) {
fn[key] = oldIO[key];
}
}
return fn;
}, {
requires: ['ajax']
});
KISSY.use = function(modules, callback) {
var args = arguments;
if (modules instanceof Array || typeof modules === 'string') {
args[0] = replace(modules);
}
KISSY.oldUse.apply(this, args);
};
KISSY.add = function(name, fn, options) {
if (options && options.requires) {
for (var i = 0, l = options.requires.length; i < l; i++) {
var current = options.requires[i].toLowerCase();
if (current == 'io' || current == 'ajax') {
options.requires[i] = 'rap_io';
}
}
}
KISSY.oldAdd.apply(this, arguments);
};
if (KISSY.IO || KISSY.io || KISSY.ajax) {
KISSY.use('rap_io', function() {});
}
}*/
}
/*if (window.define && window.define.cmd) {
var data = seajs.config().data;
data.alias = data.alias || {};
var path = 'http://' + ROOT + '/stat/js/util/jquery-rapped.js';
data.alias.jquery = data.alias.jQuery = data.alias.jq = data.alias.jQ = data.alias.$ = path;
}
function replace(modules) {
var splited = modules;
if (KISSY.isString(modules)) {
splited = modules.split(',');
}
var index = -1;
for (var i = 0, l = splited.length; i < l; i++) {
var name = KISSY.trim(splited[i]).toLowerCase();
if (name === 'ajax' || name === 'io') {
splited[i] = 'rap_io';
}
}
return splited.join(',');
}
*/
function checkerHandler(mockData) {
if (PREFIX == '/mockjs/') {
mockData = Mock.mock(mockData);
}
var realData = this.data;
var validator = new StructureValidator(realData, mockData);
var result = validator.getResult();
var realDataResult = result.left;
var rapDataResult = result.right;
var i;
var log = [];
var error = false;
if (realDataResult.length === 0 && rapDataResult.length === 0) {
log.push('接口结构校验完毕,未发现问题。');
} else {
error = true;
if (this.url) {
log.push('在校验接口' + this.url + '时发现错误:');
}
for (i = 0; i < realDataResult.length; i++) {
log.push(validatorResultLog(realDataResult[i]));
}
for (i = 0; i < rapDataResult.length; i++) {
log.push(validatorResultLog(rapDataResult[i], true));
}
}
console.info(log.join('\n'));
if (error === true) {
console.log('真实数据:');
console.dir(this.data);
}
}
/**
* is in white list
*
*/
function isInWhiteList(url) {
var i;
var o;
for (i = 0; i < whiteList.length; i++) {
o = whiteList[i];
if (typeof o === 'string' && (url.indexOf(o) >= 0 || o.indexOf(url) >= 0)) {
return true;
} else if (typeof o === 'object' && o instanceof RegExp && o.test(url)) {
return true;
}
}
return false;
}
/**
* router
*
* @param {string} url
* @return {boolean} true if route to RAP MOCK, other wise do nothing.
*/
function route(url, ignoreMode) {
var i;
var o;
var blackMode;
var list;
url = convertUrlToRelative(url);
if (!url || typeof url !== 'string') {
console.warn("Illegal url:", url);
return false;
}
/**
* disabled
*/
if (mode === 0) {
return false;
}
/**
* intercept all requests
*/
else if (mode == 1) {
return true;
}
/**
* black/white list mode
*/
else if (mode === 2 || mode === 3) {
blackMode = mode === 2;
list = blackMode ? blackList : whiteList;
for (i = 0; i < list.length; i++) {
o = convertUrlToRelative(list[i]);
if (typeof o === 'string' && (url.indexOf(o) >= 0 || o.indexOf(url) >= 0)) {
return !blackMode;
} else if (typeof o === 'object' && o instanceof RegExp && o.test(url)) {
return !blackMode;
}
}
return blackMode;
}
return false;
}
function validatorResultLog(item, isReverse) {
var eventName;
if (item.type === LOST) {
eventName = isReverse ? '未在接口文档中未定义。' : '缺失';
} else if (item.type === EMPTY_ARRAY) {
eventName = '数组为空,无法判断其内部的结构。';
return; // 暂时忽略此种情况
} else if (item.type === TYPE_NOT_EQUAL) {
eventName = '数据类型与接口文档中的定义不符';
}
return '参数 ' + item.namespace + "." + item.property + ' ' + eventName;
}
/**
* convert url from absolute to relative
*/
function convertUrlToRelative(url) {
if (url instanceof RegExp) {
return url;
}
if (!url) {
throw Error('Illegal url:' + url);
}
if (url.indexOf('http://') > -1) {
url = url.substring(url.indexOf('/', 7) + 1);
} else if (url.indexOf('https://') > -1) {
url = url.substring(url.indexOf('/', 8) + 1);
}
if (url.charAt(0) != '/') {
url = '/' + url;
}
return url;
}
/**
* convert url to rap mock url (KISSY version)
* example: www.baidu.com/a => domain/mock/106/a
*/
function rapUrlConverterKissy(options) {
var url = options.url;
if (!options || typeof options !== 'object') {
throw Error('illegal option object:' + options);
}
options.type = "get";
options.jsonp = '_c';
options.dataType = 'jsonp';
url = convertUrlToRelative(url);
url = "http://" + ROOT + PREFIX + projectId + url;
options.url = url;
return options;
}
/**
* convert url to rap mock url (jQuery version)
* example: www.baidu.com/a => domain/mock/106/a
*/
function rapUrlConverterJQuery(options) {
var url = options.url;
if (!options || typeof options !== 'object') {
throw Error('illegal option object:' + options);
}
options.jsonp = '_c';
options.dataType = 'jsonp';
url = convertUrlToRelative(url);
url = "http://" + ROOT + PREFIX + projectId + url;
options.url = url;
return options;
}
window.RAP = {
initList: function (list) {
var PARAM_REG = /\/:[^\/]*/g;
var i, n = list.length,
item;
for (i = 0; i < n; i++) {
item = list[i];
if (typeof item === 'string') {
if (PARAM_REG.test(item)) {
item = new RegExp(item.replace(PARAM_REG, '/\\d+'));
list[i] = item;
} else if (item.indexOf('reg:') !== -1) {
item = item.replace('reg:', '');
item = new RegExp(item);
list[i] = item;
}
}
}
return list;
},
setBlackList: function (arr) {
if (arr && arr instanceof Array) {
blackList = this.initList(arr);
}
},
setWhiteList: function (arr) {
if (arr && arr instanceof Array) {
whiteList = this.initList(arr);
}
},
getBlackList: function () {
return blackList;
},
getWhiteList: function () {
return whiteList;
},
getMode: function () {
return mode;
},
setMode: function (m) {
m = +m;
if (m in modeList) {
mode = m;
console.log('RAP work mode switched to ', m);
} else {
console.warn('Illegal mode id. Please check.');
}
},
setHost: function (h) {
ROOT = h;
},
getHost: function () {
return ROOT;
},
setPrefix: function (p) {
PREFIX = p;
},
getPrefix: function (p) {
return PREFIX;
},
setProjectId: function (id) {
projectId = id;
},
getProjectId: function () {
return projectId;
}
};
RAP.initList(whiteList);
})();