Skip to content

Using serverUrl constant for batch requests. #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ParseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ var objectCount = 0;
// behavior in a server scenario
var singleInstance = (!CoreManager.get('IS_NODE'));

function getServerUrlPath() {
var serverUrl = CoreManager.get('SERVER_URL');
if (serverUrl[serverUrl.length - 1] !== '/') {
serverUrl += '/';
}
var url = serverUrl.replace(/https?:\/\//, '');
return url.substr(url.indexOf('/'));
}

/**
* Creates a new model with defined attributes.
*
Expand Down Expand Up @@ -1576,7 +1585,7 @@ var DefaultController = {
requests: batch.map((obj) => {
return {
method: 'DELETE',
path: '/1/classes/' + obj.className + '/' + obj._getId(),
path: getServerUrlPath() + 'classes/' + obj.className + '/' + obj._getId(),
body: {}
};
})
Expand Down Expand Up @@ -1700,7 +1709,7 @@ var DefaultController = {
return RESTController.request('POST', 'batch', {
requests: batch.map((obj) => {
var params = obj._getSaveParams();
params.path = '/1/' + params.path;
params.path = getServerUrlPath() + params.path;
return params;
})
}, options);
Expand Down