@@ -18,40 +18,39 @@ function parseURL(URL) {
18
18
return undefined ;
19
19
}
20
20
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 ;
24
24
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 ) ;
27
27
28
- let makeRoutablePath = function ( requestPath ) {
28
+ let makeRoutablePath = function ( requestPath ) {
29
29
// 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 (
32
32
Parse . Error . INVALID_JSON ,
33
- 'cannot route batch path ' + path ) ;
34
- }
35
- return path . join ( '/' , requestPath . slice ( apiPrefixLength ) ) ;
33
+ 'cannot route batch path ' + requestPath ) ;
36
34
}
35
+ return path . join ( '/' , requestPath . slice ( apiPrefix . length ) ) ;
36
+ }
37
37
38
- if ( serverURL && publicServerURL
38
+ if ( serverURL && publicServerURL
39
39
&& ( serverURL . path != publicServerURL . path ) ) {
40
- let localPath = serverURL . path ;
41
- let publicPath = publicServerURL . path ;
40
+ let localPath = serverURL . path ;
41
+ let publicPath = publicServerURL . path ;
42
42
// Override the api prefix
43
- apiPrefix = localPath ;
44
- apiPrefixLength = localPath . length ;
45
- return function ( requestPath ) {
43
+ apiPrefix = localPath ;
44
+ return function ( requestPath ) {
46
45
// Build the new path by removing the public path
47
46
// 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 ) ) ;
49
48
// Use the method for local routing
50
- return makeRoutablePath ( newPath ) ;
51
- }
49
+ return makeRoutablePath ( newPath ) ;
52
50
}
51
+ }
53
52
54
- return makeRoutablePath ;
53
+ return makeRoutablePath ;
55
54
}
56
55
57
56
// Returns a promise for a {response} object.
@@ -71,7 +70,7 @@ function handleBatch(router, req) {
71
70
throw 'internal routing problem - expected url to end with batch' ;
72
71
}
73
72
74
- const makeRoutablePath = mBatchRoutingPath ( req . originalUrl , req . config . serverURL , req . config . publicServerURL ) ;
73
+ const makeRoutablePath = makeBatchRoutingPathFunction ( req . originalUrl , req . config . serverURL , req . config . publicServerURL ) ;
75
74
76
75
const promises = req . body . requests . map ( ( restRequest ) => {
77
76
const routablePath = makeRoutablePath ( restRequest . path ) ;
@@ -97,5 +96,5 @@ function handleBatch(router, req) {
97
96
98
97
module . exports = {
99
98
mountOnto,
100
- mBatchRoutingPath
99
+ makeBatchRoutingPathFunction
101
100
} ;
0 commit comments