1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function (define) {
|
9 | 'use strict';
|
10 |
|
11 | define(function (require) {
|
12 |
|
13 | var interceptor, UrlBuilder;
|
14 |
|
15 | interceptor = require('../interceptor');
|
16 | UrlBuilder = require('../UrlBuilder');
|
17 |
|
18 | function startsWith(str, prefix) {
|
19 | return str.indexOf(prefix) === 0;
|
20 | }
|
21 |
|
22 | function endsWith(str, suffix) {
|
23 | return str.lastIndexOf(suffix) + suffix.length === str.length;
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | return interceptor({
|
35 | request: function (request, config) {
|
36 | var path;
|
37 |
|
38 | if (config.prefix && !(new UrlBuilder(request.path).isFullyQualified())) {
|
39 | path = config.prefix;
|
40 | if (request.path) {
|
41 | if (!endsWith(path, '/') && !startsWith(request.path, '/')) {
|
42 |
|
43 | path += '/';
|
44 | }
|
45 | path += request.path;
|
46 | }
|
47 | request.path = path;
|
48 | }
|
49 |
|
50 | return request;
|
51 | }
|
52 | });
|
53 |
|
54 | });
|
55 |
|
56 | }(
|
57 | typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
|
58 |
|
59 | ));
|