Skip to content

Properly handle serverURL and publicServerUrl in Batch requests #6980 #7049

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 2 commits into from
Dec 9, 2020

Conversation

ZachGoldberg
Copy link
Contributor

See #6980 for more context

I'm not 100% confident I understand the intended distinction between serverUrl and publicServerUrl but my instinct is that on a production machine I should be able to access parse server via either URL. That seems to be the case for everything BUT batch requests which have an assumption that requests come only from the pubic URL. This patch has a rough-shod attempt at a quick-and-dirty detection of which kind of URL is being used to construct the newPath appropriately.

The included test fails before the patch, passes afterwards.

@codecov
Copy link

codecov bot commented Dec 8, 2020

Codecov Report

Merging #7049 (9336ab8) into master (b398894) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7049      +/-   ##
==========================================
- Coverage   93.86%   93.84%   -0.03%     
==========================================
  Files         169      169              
  Lines       12437    12440       +3     
==========================================
  Hits        11674    11674              
- Misses        763      766       +3     
Impacted Files Coverage Δ
src/batch.js 92.30% <100.00%> (+0.47%) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <0.00%> (-0.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b398894...9336ab8. Read the comment docs.

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick nit. Looks good to me.

const startsWithPublic = requestPath.startsWith(publicPath);
const pathLengthToUse =
startsWithLocal && startsWithPublic
? Math.max(localPath.length, publicPath.length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a second to figure out what this was doing. Good way to tell which one "startsWith" more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about this... I wrote this four times trying to find a clear way to do it and am still unhappy with the readability... definitely open to suggestions on strategy or clarity here!

src/batch.js Outdated
? Math.max(localPath.length, publicPath.length)
: startsWithLocal
? localPath.length
: publicPath.length;
// Build the new path by removing the public path
// and joining with the local path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this old comment?

@dplewis dplewis requested review from davimacedo and mtrezza December 9, 2020 17:33
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@dplewis dplewis changed the title detect if the caller is accessing us via local or parse for batch requests #6980 Properly handle serverURL and publicServerUrl in Batch requests #6980 Dec 9, 2020
@dplewis dplewis merged commit abdfe61 into parse-community:master Dec 9, 2020
oobidin pushed a commit to oobidin/parse-server that referenced this pull request Oct 4, 2022
…-community#6980 (parse-community#7049)

* fix: detect if the caller is accessing us via local or parse for batch requests (parse-community#6980)

* chore: minor cleanup from PR
oobidin pushed a commit to oobidin/parse-server that referenced this pull request Nov 29, 2022
…-community#6980 (parse-community#7049)

* fix: detect if the caller is accessing us via local or parse for batch requests (parse-community#6980)

* chore: minor cleanup from PR
oobidin pushed a commit to revolut-engineering/parse-server that referenced this pull request Nov 29, 2022
…-community#6980 (parse-community#7049)

* fix: detect if the caller is accessing us via local or parse for batch requests (parse-community#6980)

* chore: minor cleanup from PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants