http-proxy-middleware 0.17.0 → 0.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +21 -6
- package/lib/handlers.js +13 -1
- package/lib/index.js +33 -10
- package/lib/logger.js +2 -2
- package/package.json +16 -12
- package/.editorconfig +0 -18
- package/.jscsrc +0 -8
- package/.npmignore +0 -28
- package/.travis.yml +0 -16
- package/CONTRIBUTING.md +0 -61
- package/ISSUE_TEMPLATE.md +0 -21
- package/examples/README.md +0 -33
- package/examples/browser-sync/index.js +0 -29
- package/examples/connect/index.js +0 -29
- package/examples/express/index.js +0 -28
- package/examples/websocket/index.html +0 -96
- package/examples/websocket/index.js +0 -41
- package/recipes/README.md +0 -110
- package/recipes/basic.md +0 -32
- package/recipes/context-matching.md +0 -99
- package/recipes/corporate-proxy.md +0 -21
- package/recipes/delay.md +0 -37
- package/recipes/logLevel.md +0 -40
- package/recipes/logProvider.md +0 -77
- package/recipes/modify-post.md +0 -74
- package/recipes/pathRewrite.md +0 -93
- package/recipes/proxy-events.md +0 -74
- package/recipes/router.md +0 -83
- package/recipes/servers.md +0 -252
- package/recipes/shorthand.md +0 -63
- package/recipes/virtual-hosts.md +0 -18
- package/recipes/websocket.md +0 -41
- package/test/e2e/_utils.js +0 -21
- package/test/e2e/http-proxy-middleware.spec.js +0 -672
- package/test/e2e/path-rewriter.spec.js +0 -98
- package/test/e2e/router.spec.js +0 -128
- package/test/e2e/websocket.spec.js +0 -150
- package/test/unit/_libs.js +0 -8
- package/test/unit/config-factory.spec.js +0 -154
- package/test/unit/context-matcher.spec.js +0 -250
- package/test/unit/handlers.spec.js +0 -126
- package/test/unit/logger.spec.js +0 -259
- package/test/unit/path-rewriter.spec.js +0 -143
- package/test/unit/router.spec.js +0 -136
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
var utils = require('./_utils');
|
|
2
|
-
var expect = require('chai').expect;
|
|
3
|
-
var http = require('http');
|
|
4
|
-
|
|
5
|
-
describe('E2E pathRewrite', function() {
|
|
6
|
-
var createServer;
|
|
7
|
-
var proxyMiddleware;
|
|
8
|
-
|
|
9
|
-
beforeEach(function() {
|
|
10
|
-
createServer = utils.createServer;
|
|
11
|
-
proxyMiddleware = utils.proxyMiddleware;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
var targetMiddleware;
|
|
15
|
-
var targetData;
|
|
16
|
-
|
|
17
|
-
beforeEach(function() {
|
|
18
|
-
targetData = {};
|
|
19
|
-
targetMiddleware = function(req, res, next) {
|
|
20
|
-
targetData.url = req.url; // store target url.
|
|
21
|
-
targetData.headers = req.headers; // store target headers.
|
|
22
|
-
res.write(req.url); // respond with target url.
|
|
23
|
-
res.end();
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
var proxyServer;
|
|
28
|
-
var targetServer;
|
|
29
|
-
|
|
30
|
-
beforeEach(function() {
|
|
31
|
-
targetServer = createServer(8000, targetMiddleware);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(function() {
|
|
35
|
-
proxyServer && proxyServer.close();
|
|
36
|
-
targetServer.close();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('Rewrite paths with rules table', function() {
|
|
40
|
-
beforeEach(function() {
|
|
41
|
-
var proxyConfig = {
|
|
42
|
-
target: 'http://localhost:8000',
|
|
43
|
-
pathRewrite: {
|
|
44
|
-
'^/foobar/api/': '/api/'
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var proxy = proxyMiddleware(proxyConfig);
|
|
48
|
-
proxyServer = createServer(3000, proxy);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
beforeEach(function(done) {
|
|
52
|
-
http.get('http://localhost:3000/foobar/api/lorum/ipsum', function(res) {
|
|
53
|
-
done();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should remove "/foobar" from path', function() {
|
|
58
|
-
expect(targetData.url).to.equal('/api/lorum/ipsum');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('Rewrite paths with function', function() {
|
|
63
|
-
var originalPath;
|
|
64
|
-
var pathRewriteReqObject;
|
|
65
|
-
|
|
66
|
-
beforeEach(function() {
|
|
67
|
-
var proxyConfig = {
|
|
68
|
-
target: 'http://localhost:8000',
|
|
69
|
-
pathRewrite: function(path, req) {
|
|
70
|
-
originalPath = path;
|
|
71
|
-
pathRewriteReqObject = req;
|
|
72
|
-
return path.replace('/foobar', '');
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var proxy = proxyMiddleware(proxyConfig);
|
|
76
|
-
proxyServer = createServer(3000, proxy);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
beforeEach(function(done) {
|
|
80
|
-
http.get('http://localhost:3000/foobar/api/lorum/ipsum', function(res) {
|
|
81
|
-
done();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should remove "/foobar" from path', function() {
|
|
86
|
-
expect(targetData.url).to.equal('/api/lorum/ipsum');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should provide the `path` parameter with the unmodified path value', function() {
|
|
90
|
-
expect(originalPath).to.equal('/foobar/api/lorum/ipsum');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should provide the `req` object as second parameter of the rewrite function', function() {
|
|
94
|
-
expect(pathRewriteReqObject.method).to.equal('GET');
|
|
95
|
-
expect(pathRewriteReqObject.url).to.equal('/api/lorum/ipsum');
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
package/test/e2e/router.spec.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
var utils = require('./_utils');
|
|
2
|
-
var expect = require('chai').expect;
|
|
3
|
-
var http = require('http');
|
|
4
|
-
|
|
5
|
-
describe('E2E router', function() {
|
|
6
|
-
var proxyServer, targetServerA, targetServerB, targetServerC;
|
|
7
|
-
var createServer;
|
|
8
|
-
var proxyMiddleware;
|
|
9
|
-
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
createServer = utils.createServer;
|
|
12
|
-
proxyMiddleware = utils.proxyMiddleware;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
beforeEach(function() {
|
|
16
|
-
targetServerA = createServer(6001, function(req, res, next) {
|
|
17
|
-
res.write('A');
|
|
18
|
-
res.end();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
targetServerB = createServer(6002, function(req, res, next) {
|
|
22
|
-
res.write('B');
|
|
23
|
-
res.end();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
targetServerC = createServer(6003, function(req, res, next) {
|
|
27
|
-
res.write('C');
|
|
28
|
-
res.end();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
afterEach(function() {
|
|
33
|
-
targetServerA.close();
|
|
34
|
-
targetServerB.close();
|
|
35
|
-
targetServerC.close();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('router with proxyTable', function() {
|
|
39
|
-
beforeEach(function() {
|
|
40
|
-
proxyServer = createServer(6000, proxyMiddleware({
|
|
41
|
-
target: 'http://localhost:6001',
|
|
42
|
-
router: function(req) {
|
|
43
|
-
return 'http://localhost:6003';
|
|
44
|
-
}
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
afterEach(function() {
|
|
49
|
-
proxyServer.close();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should proxy to: "localhost:6003/api"', function(done) {
|
|
53
|
-
var options = {hostname: 'localhost', port: 6000, path: '/api'};
|
|
54
|
-
http.get(options, function(res) {
|
|
55
|
-
res.on('data', function(chunk) {
|
|
56
|
-
var responseBody = chunk.toString();
|
|
57
|
-
expect(responseBody).to.equal('C');
|
|
58
|
-
done();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('router with proxyTable', function() {
|
|
66
|
-
|
|
67
|
-
beforeEach(function setupServers() {
|
|
68
|
-
proxyServer = createServer(6000, proxyMiddleware('/', {
|
|
69
|
-
target: 'http://localhost:6001',
|
|
70
|
-
router: {
|
|
71
|
-
'alpha.localhost:6000': 'http://localhost:6001',
|
|
72
|
-
'beta.localhost:6000': 'http://localhost:6002',
|
|
73
|
-
'localhost:6000/api': 'http://localhost:6003'
|
|
74
|
-
}
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
afterEach(function() {
|
|
80
|
-
proxyServer.close();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should proxy to option.target', function(done) {
|
|
84
|
-
http.get('http://localhost:6000', function(res) {
|
|
85
|
-
res.on('data', function(chunk) {
|
|
86
|
-
var responseBody = chunk.toString();
|
|
87
|
-
expect(responseBody).to.equal('A');
|
|
88
|
-
done();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should proxy when host is "alpha.localhost"', function(done) {
|
|
94
|
-
var options = {hostname: 'localhost', port: 6000, path: '/'};
|
|
95
|
-
options.headers = {host: 'alpha.localhost:6000'};
|
|
96
|
-
http.get(options, function(res) {
|
|
97
|
-
res.on('data', function(chunk) {
|
|
98
|
-
var responseBody = chunk.toString();
|
|
99
|
-
expect(responseBody).to.equal('A');
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should proxy when host is "beta.localhost"', function(done) {
|
|
106
|
-
var options = {hostname: 'localhost', port: 6000, path: '/'};
|
|
107
|
-
options.headers = {host: 'beta.localhost:6000'};
|
|
108
|
-
http.get(options, function(res) {
|
|
109
|
-
res.on('data', function(chunk) {
|
|
110
|
-
var responseBody = chunk.toString();
|
|
111
|
-
expect(responseBody).to.equal('B');
|
|
112
|
-
done();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should proxy with host & path config: "localhost:6000/api"', function(done) {
|
|
118
|
-
var options = {hostname: 'localhost', port: 6000, path: '/api'};
|
|
119
|
-
http.get(options, function(res) {
|
|
120
|
-
res.on('data', function(chunk) {
|
|
121
|
-
var responseBody = chunk.toString();
|
|
122
|
-
expect(responseBody).to.equal('C');
|
|
123
|
-
done();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
var utils = require('./_utils');
|
|
2
|
-
var expect = require('chai').expect;
|
|
3
|
-
var http = require('http');
|
|
4
|
-
var WebSocket = require('ws');
|
|
5
|
-
var WebSocketServer = require('ws').Server;
|
|
6
|
-
|
|
7
|
-
describe('E2E WebSocket proxy', function() {
|
|
8
|
-
var createServer;
|
|
9
|
-
var proxyMiddleware;
|
|
10
|
-
|
|
11
|
-
beforeEach(function() {
|
|
12
|
-
createServer = utils.createServer;
|
|
13
|
-
proxyMiddleware = utils.proxyMiddleware;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
var proxyServer, ws, wss;
|
|
17
|
-
var targetHeaders;
|
|
18
|
-
var responseMessage;
|
|
19
|
-
var proxy;
|
|
20
|
-
|
|
21
|
-
beforeEach(function() {
|
|
22
|
-
proxy = proxyMiddleware('/', {
|
|
23
|
-
target: 'http://localhost:8000',
|
|
24
|
-
ws: true,
|
|
25
|
-
pathRewrite: {'^/socket': ''}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
proxyServer = createServer(3000, proxy);
|
|
29
|
-
|
|
30
|
-
wss = new WebSocketServer({port: 8000});
|
|
31
|
-
|
|
32
|
-
wss.on('connection', function connection(ws) {
|
|
33
|
-
ws.on('message', function incoming(message) {
|
|
34
|
-
ws.send(message); // echo received message
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('option.ws', function() {
|
|
40
|
-
beforeEach(function(done) {
|
|
41
|
-
// need to make a normal http request,
|
|
42
|
-
// so http-proxy-middleware can catch the upgrade request
|
|
43
|
-
http.get('http://localhost:3000/', function() {
|
|
44
|
-
// do a second http request to make
|
|
45
|
-
// sure only 1 listener subscribes to upgrade request
|
|
46
|
-
http.get('http://localhost:3000/', function() {
|
|
47
|
-
ws = new WebSocket('ws://localhost:3000/socket');
|
|
48
|
-
|
|
49
|
-
ws.on('message', function incoming(message) {
|
|
50
|
-
responseMessage = message;
|
|
51
|
-
done();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
ws.on('open', function open() {
|
|
55
|
-
ws.send('foobar');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should proxy to path', function() {
|
|
62
|
-
expect(responseMessage).to.equal('foobar');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('option.ws with external server "upgrade"', function() {
|
|
67
|
-
beforeEach(function(done) {
|
|
68
|
-
proxyServer.on('upgrade', proxy.upgrade);
|
|
69
|
-
|
|
70
|
-
ws = new WebSocket('ws://localhost:3000/socket');
|
|
71
|
-
|
|
72
|
-
ws.on('message', function incoming(message) {
|
|
73
|
-
responseMessage = message;
|
|
74
|
-
done();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
ws.on('open', function open() {
|
|
78
|
-
ws.send('foobar');
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should proxy to path', function() {
|
|
83
|
-
expect(responseMessage).to.equal('foobar');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('option.ws with external server "upgrade" and shorthand usage', function() {
|
|
88
|
-
|
|
89
|
-
beforeEach(function() {
|
|
90
|
-
proxyServer.close();
|
|
91
|
-
// override
|
|
92
|
-
proxy = proxyMiddleware('ws://localhost:8000', {pathRewrite: {'^/socket': ''}});
|
|
93
|
-
proxyServer = createServer(3000, proxy);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
beforeEach(function(done) {
|
|
97
|
-
proxyServer.on('upgrade', proxy.upgrade);
|
|
98
|
-
|
|
99
|
-
ws = new WebSocket('ws://localhost:3000/socket');
|
|
100
|
-
|
|
101
|
-
ws.on('message', function incoming(message) {
|
|
102
|
-
responseMessage = message;
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
ws.on('open', function open() {
|
|
107
|
-
ws.send('foobar');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should proxy to path', function() {
|
|
112
|
-
expect(responseMessage).to.equal('foobar');
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('with proxyTable and pathRewrite', function() {
|
|
117
|
-
|
|
118
|
-
beforeEach(function() {
|
|
119
|
-
proxyServer.close();
|
|
120
|
-
// override
|
|
121
|
-
proxy = proxyMiddleware('ws://notworkinghost:6789', {proxyTable: {'/socket': 'ws://localhost:8000'}, pathRewrite: {'^/socket': ''}});
|
|
122
|
-
proxyServer = createServer(3000, proxy);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
beforeEach(function(done) {
|
|
126
|
-
proxyServer.on('upgrade', proxy.upgrade);
|
|
127
|
-
|
|
128
|
-
ws = new WebSocket('ws://localhost:3000/socket');
|
|
129
|
-
|
|
130
|
-
ws.on('message', function incoming(message) {
|
|
131
|
-
responseMessage = message;
|
|
132
|
-
done();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
ws.on('open', function open() {
|
|
136
|
-
ws.send('foobar');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should proxy to path', function() {
|
|
141
|
-
expect(responseMessage).to.equal('foobar');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
afterEach(function() {
|
|
146
|
-
proxyServer.close();
|
|
147
|
-
wss.close();
|
|
148
|
-
ws = null;
|
|
149
|
-
});
|
|
150
|
-
});
|
package/test/unit/_libs.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
configFactory: require('../../lib/config-factory'),
|
|
3
|
-
contextMatcher: require('../../lib/context-matcher'),
|
|
4
|
-
handlers: require('../../lib/handlers'),
|
|
5
|
-
Logger: require('../../lib/logger'),
|
|
6
|
-
pathRewriter: require('../../lib/path-rewriter'),
|
|
7
|
-
router: require('../../lib/router')
|
|
8
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var configFactory = require('./_libs').configFactory;
|
|
3
|
-
|
|
4
|
-
describe('configFactory', function() {
|
|
5
|
-
var result;
|
|
6
|
-
var createConfig = configFactory.createConfig;
|
|
7
|
-
|
|
8
|
-
describe('createConfig()', function() {
|
|
9
|
-
|
|
10
|
-
describe('classic config', function() {
|
|
11
|
-
var context = '/api';
|
|
12
|
-
var options = {target: 'http://www.example.org'};
|
|
13
|
-
|
|
14
|
-
beforeEach(function() {
|
|
15
|
-
result = createConfig(context, options);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return config object', function() {
|
|
19
|
-
expect(result).to.have.all.keys('context', 'options');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should return config object with context', function() {
|
|
23
|
-
expect(result.context).to.equal(context);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should return config object with options', function() {
|
|
27
|
-
expect(result.options).to.deep.equal(options);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('shorthand String', function() {
|
|
32
|
-
describe('shorthand String config', function() {
|
|
33
|
-
beforeEach(function() {
|
|
34
|
-
result = createConfig('http://www.example.org:8000/api');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return config object', function() {
|
|
38
|
-
expect(result).to.have.all.keys('context', 'options');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should return config object with context', function() {
|
|
42
|
-
expect(result.context).to.equal('/api');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should return config object with options', function() {
|
|
46
|
-
expect(result.options).to.deep.equal({target: 'http://www.example.org:8000'});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('shorthand String config for whole domain', function() {
|
|
51
|
-
beforeEach(function() {
|
|
52
|
-
result = createConfig('http://www.example.org:8000');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should return config object with context', function() {
|
|
56
|
-
expect(result.context).to.equal('/');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('shorthand String config for websocket url', function() {
|
|
61
|
-
beforeEach(function() {
|
|
62
|
-
result = createConfig('ws://www.example.org:8000');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should return config object with context', function() {
|
|
66
|
-
expect(result.context).to.equal('/');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should return options with ws = true', function() {
|
|
70
|
-
expect(result.options.ws).to.equal(true);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('shorthand String config for secure websocket url', function() {
|
|
75
|
-
beforeEach(function() {
|
|
76
|
-
result = createConfig('wss://www.example.org:8000');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should return config object with context', function() {
|
|
80
|
-
expect(result.context).to.equal('/');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should return options with ws = true', function() {
|
|
84
|
-
expect(result.options.ws).to.equal(true);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('shorthand String config with globbing', function() {
|
|
89
|
-
beforeEach(function() {
|
|
90
|
-
result = createConfig('http://www.example.org:8000/api/*.json');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should return config object with context', function() {
|
|
94
|
-
expect(result.context).to.equal('/api/*.json');
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('shorthand String config with options', function() {
|
|
99
|
-
beforeEach(function() {
|
|
100
|
-
result = createConfig('http://www.example.org:8000/api', {changeOrigin: true});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should return config object with additional options', function() {
|
|
104
|
-
expect(result.options).to.deep.equal({target: 'http://www.example.org:8000', changeOrigin: true});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('shorthand Object config', function() {
|
|
110
|
-
beforeEach(function() {
|
|
111
|
-
result = createConfig({target: 'http://www.example.org:8000'});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should set the proxy path to everything', function() {
|
|
115
|
-
expect(result.context).to.equal('/');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should return config object', function() {
|
|
119
|
-
expect(result.options).to.deep.equal({target: 'http://www.example.org:8000'});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('missing option.target', function() {
|
|
124
|
-
var fn;
|
|
125
|
-
beforeEach(function() {
|
|
126
|
-
fn = function() {
|
|
127
|
-
createConfig('/api');
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should throw an error when target option is missing', function() {
|
|
132
|
-
expect(fn).to.throw(Error);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('faulty config. mixing classic with shorthand', function() {
|
|
137
|
-
var fn;
|
|
138
|
-
beforeEach(function() {
|
|
139
|
-
result = createConfig('http://localhost:3000/api', {target: 'http://localhost:8000'});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should use the target in the configuration as target', function() {
|
|
143
|
-
expect(result.options.target).to.equal('http://localhost:8000');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should not use the host from the shorthand as target', function() {
|
|
147
|
-
expect(result.options.target).not.to.equal('http://localhost:3000');
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
|