Skip to content

Commit e5f1bd0

Browse files
committed
nits
1 parent da4a490 commit e5f1bd0

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

spec/batch.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@ const serverURLNaked = 'http://localhost:1234/';
77
const publicServerURL = 'http://domain.com/parse';
88
const publicServerURLNaked = 'http://domain.com/';
99

10-
describe('batch', () => {
11-
it('should return the proper url', () => {
12-
let internalURL = batch.mBatchRoutingPath(originalURL)('/parse/classes/Object');
10+
describe('batch', () => {
11+
it('should return the proper url', () => {
12+
let internalURL = batch.makeBatchRoutingPathFunction(originalURL)('/parse/classes/Object');
1313

1414
expect(internalURL).toEqual('/classes/Object');
1515
});
1616

17-
it('should return the proper url same public/local endpoint', () => {
17+
it('should return the proper url same public/local endpoint', () => {
1818
let originalURL = '/parse/batch';
19-
let internalURL = batch.mBatchRoutingPath(originalURL, serverURL, publicServerURL)('/parse/classes/Object');
19+
let internalURL = batch.makeBatchRoutingPathFunction(originalURL, serverURL, publicServerURL)('/parse/classes/Object');
2020

2121
expect(internalURL).toEqual('/classes/Object');
2222
});
2323

24-
it('should return the proper url with different public/local mount', () => {
24+
it('should return the proper url with different public/local mount', () => {
2525
let originalURL = '/parse/batch';
26-
let internalURL = batch.mBatchRoutingPath(originalURL, serverURL1, publicServerURL)('/parse/classes/Object');
26+
let internalURL = batch.makeBatchRoutingPathFunction(originalURL, serverURL1, publicServerURL)('/parse/classes/Object');
2727

2828
expect(internalURL).toEqual('/classes/Object');
2929
});
3030

31-
it('should return the proper url with naked public', () => {
31+
it('should return the proper url with naked public', () => {
3232
let originalURL = '/batch';
33-
let internalURL = batch.mBatchRoutingPath(originalURL, serverURL, publicServerURLNaked)('/classes/Object');
33+
let internalURL = batch.makeBatchRoutingPathFunction(originalURL, serverURL, publicServerURLNaked)('/classes/Object');
3434

3535
expect(internalURL).toEqual('/classes/Object');
3636
});
3737

38-
it('should return the proper url with naked local', () => {
38+
it('should return the proper url with naked local', () => {
3939
let originalURL = '/parse/batch';
40-
let internalURL = batch.mBatchRoutingPath(originalURL, serverURLNaked, publicServerURL)('/parse/classes/Object');
40+
let internalURL = batch.makeBatchRoutingPathFunction(originalURL, serverURLNaked, publicServerURL)('/parse/classes/Object');
4141

4242
expect(internalURL).toEqual('/classes/Object');
4343
});
44-
});
44+
});

src/batch.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,39 @@ function parseURL(URL) {
1818
return undefined;
1919
}
2020

21-
function mBatchRoutingPath(originalUrl, serverURL, publicServerURL) {
22-
serverURL = serverURL ? parseURL(serverURL) : undefined;
23-
publicServerURL = publicServerURL ? parseURL(publicServerURL): undefined;
21+
function makeBatchRoutingPathFunction(originalUrl, serverURL, publicServerURL) {
22+
serverURL = serverURL ? parseURL(serverURL) : undefined;
23+
publicServerURL = publicServerURL ? parseURL(publicServerURL): undefined;
2424

25-
let apiPrefixLength = originalUrl.length - batchPath.length;
26-
let apiPrefix = originalUrl.slice(0, apiPrefixLength);
25+
let apiPrefixLength = originalUrl.length - batchPath.length;
26+
let apiPrefix = originalUrl.slice(0, apiPrefixLength);
2727

28-
let makeRoutablePath = function(requestPath) {
28+
let makeRoutablePath = function(requestPath) {
2929
// The routablePath is the path minus the api prefix
30-
if (requestPath.slice(0, apiPrefixLength) != apiPrefix) {
31-
throw new Parse.Error(
30+
if (requestPath.slice(0, apiPrefix.length) != apiPrefix) {
31+
throw new Parse.Error(
3232
Parse.Error.INVALID_JSON,
33-
'cannot route batch path ' + path);
34-
}
35-
return path.join('/', requestPath.slice(apiPrefixLength));
33+
'cannot route batch path ' + requestPath);
3634
}
35+
return path.join('/', requestPath.slice(apiPrefix.length));
36+
}
3737

38-
if (serverURL && publicServerURL
38+
if (serverURL && publicServerURL
3939
&& (serverURL.path != publicServerURL.path)) {
40-
let localPath = serverURL.path;
41-
let publicPath = publicServerURL.path;
40+
let localPath = serverURL.path;
41+
let publicPath = publicServerURL.path;
4242
// Override the api prefix
43-
apiPrefix = localPath;
44-
apiPrefixLength = localPath.length;
45-
return function(requestPath) {
43+
apiPrefix = localPath;
44+
return function(requestPath) {
4645
// Build the new path by removing the public path
4746
// and joining with the local path
48-
let newPath = path.join('/', localPath, '/' , requestPath.slice(publicPath.length));
47+
let newPath = path.join('/', localPath, '/' , requestPath.slice(publicPath.length));
4948
// Use the method for local routing
50-
return makeRoutablePath(newPath);
51-
}
49+
return makeRoutablePath(newPath);
5250
}
51+
}
5352

54-
return makeRoutablePath;
53+
return makeRoutablePath;
5554
}
5655

5756
// Returns a promise for a {response} object.
@@ -71,7 +70,7 @@ function handleBatch(router, req) {
7170
throw 'internal routing problem - expected url to end with batch';
7271
}
7372

74-
const makeRoutablePath = mBatchRoutingPath(req.originalUrl, req.config.serverURL, req.config.publicServerURL);
73+
const makeRoutablePath = makeBatchRoutingPathFunction(req.originalUrl, req.config.serverURL, req.config.publicServerURL);
7574

7675
const promises = req.body.requests.map((restRequest) => {
7776
const routablePath = makeRoutablePath(restRequest.path);
@@ -97,5 +96,5 @@ function handleBatch(router, req) {
9796

9897
module.exports = {
9998
mountOnto,
100-
mBatchRoutingPath
99+
makeBatchRoutingPathFunction
101100
};

0 commit comments

Comments
 (0)