(originalUrl, serverURL, publicServerURL)
| 19 | } |
| 20 | |
| 21 | function makeBatchRoutingPathFunction(originalUrl, serverURL, publicServerURL) { |
| 22 | serverURL = serverURL ? parseURL(serverURL) : undefined; |
| 23 | publicServerURL = publicServerURL ? parseURL(publicServerURL) : undefined; |
| 24 | |
| 25 | const apiPrefixLength = originalUrl.length - batchPath.length; |
| 26 | let apiPrefix = originalUrl.slice(0, apiPrefixLength); |
| 27 | |
| 28 | const makeRoutablePath = function (requestPath) { |
| 29 | // The routablePath is the path minus the api prefix |
| 30 | if (requestPath.slice(0, apiPrefix.length) != apiPrefix) { |
| 31 | throw new Parse.Error(Parse.Error.INVALID_JSON, 'cannot route batch path ' + requestPath); |
| 32 | } |
| 33 | return path.posix.join('/', requestPath.slice(apiPrefix.length)); |
| 34 | }; |
| 35 | |
| 36 | if (serverURL && publicServerURL && serverURL.pathname != publicServerURL.pathname) { |
| 37 | const localPath = serverURL.pathname; |
| 38 | const publicPath = publicServerURL.pathname; |
| 39 | |
| 40 | // Override the api prefix |
| 41 | apiPrefix = localPath; |
| 42 | return function (requestPath) { |
| 43 | // Figure out which server url was used by figuring out which |
| 44 | // path more closely matches requestPath |
| 45 | const startsWithLocal = requestPath.startsWith(localPath); |
| 46 | const startsWithPublic = requestPath.startsWith(publicPath); |
| 47 | const pathLengthToUse = |
| 48 | startsWithLocal && startsWithPublic |
| 49 | ? Math.max(localPath.length, publicPath.length) |
| 50 | : startsWithLocal |
| 51 | ? localPath.length |
| 52 | : publicPath.length; |
| 53 | |
| 54 | const newPath = path.posix.join('/', localPath, '/', requestPath.slice(pathLengthToUse)); |
| 55 | |
| 56 | // Use the method for local routing |
| 57 | return makeRoutablePath(newPath); |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | return makeRoutablePath; |
| 62 | } |
| 63 | |
| 64 | // Returns a promise for a {response} object. |
| 65 | // TODO: pass along auth correctly |
no test coverage detected