MCPcopy
hub / github.com/parse-community/parse-server / handleRequest

Function handleRequest

src/ParseServerRESTController.js:33–166  ·  view source on GitHub ↗
(method, path, data = {}, options = {}, config)

Source from the content-addressed store, hash-verified

31
32function ParseServerRESTController(applicationId, router) {
33 function handleRequest(method, path, data = {}, options = {}, config) {
34 // Store the arguments, for later use if internal fails
35 const args = arguments;
36
37 if (!config) {
38 config = Config.get(applicationId);
39 }
40 const serverURL = new URL(config.serverURL);
41 if (path.indexOf(serverURL.pathname) === 0) {
42 path = path.slice(serverURL.pathname.length, path.length);
43 }
44
45 if (path[0] !== '/') {
46 path = '/' + path;
47 }
48
49 if (path === '/batch') {
50 const batch = transactionRetries => {
51 let initialPromise = Promise.resolve();
52 if (data.transaction === true) {
53 initialPromise = config.database.createTransactionalSession();
54 }
55 return initialPromise.then(() => {
56 const promises = data.requests.map(request => {
57 return handleRequest(request.method, request.path, request.body, options, config).then(
58 response => {
59 if (options.returnStatus) {
60 const status = response._status;
61 const headers = response._headers;
62 delete response._status;
63 delete response._headers;
64 return { success: response, _status: status, _headers: headers };
65 }
66 return { success: response };
67 },
68 error => {
69 return {
70 error: { code: error.code, error: error.message },
71 };
72 }
73 );
74 });
75 return Promise.all(promises)
76 .then(result => {
77 if (data.transaction === true) {
78 if (result.find(resultItem => typeof resultItem.error === 'object')) {
79 return config.database.abortTransactionalSession().then(() => {
80 return Promise.reject(result);
81 });
82 } else {
83 return config.database.commitTransactionalSession().then(() => {
84 return result;
85 });
86 }
87 } else {
88 return result;
89 }
90 })

Callers 1

batchFunction · 0.85

Calls 5

getAuthFunction · 0.85
tryRouteRequestMethod · 0.80
batchFunction · 0.70
resolveFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected