-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: add allowHeaders to Options #6044
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
davimacedo
merged 5 commits into
parse-community:master
from
omairvaiyani:configure-allowed-headers
Sep 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c14cf9c
feat: add allowHeaders to Options
omairvaiyani 0e974ed
refactor: convert allowCrossDomain to generator to add appId in scope
omairvaiyani 270aa84
chore: update Definitions and docs
omairvaiyani 4d87fed
fix: update test to use new allowCrossDomain params
omairvaiyani 4cf0383
chore: add tests for allowCustomDomain middleware re: allowHeadrs
omairvaiyani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,20 @@ import Config from './Config'; | |
import ClientSDK from './ClientSDK'; | ||
import defaultLogger from './logger'; | ||
|
||
const getMountForRequest = function(req) { | ||
const mountPathLength = req.originalUrl.length - req.url.length; | ||
const mountPath = req.originalUrl.slice(0, mountPathLength); | ||
return req.protocol + '://' + req.get('host') + mountPath; | ||
}; | ||
|
||
// Checks that the request is authorized for this app and checks user | ||
// auth too. | ||
// The bodyparser should run before this middleware. | ||
// Adds info to the request: | ||
// req.config - the Config for this app | ||
// req.auth - the Auth for this request | ||
export function handleParseHeaders(req, res, next) { | ||
var mountPathLength = req.originalUrl.length - req.url.length; | ||
var mountPath = req.originalUrl.slice(0, mountPathLength); | ||
var mount = req.protocol + '://' + req.get('host') + mountPath; | ||
var mount = getMountForRequest(req); | ||
|
||
var info = { | ||
appId: req.get('X-Parse-Application-Id'), | ||
|
@@ -280,12 +284,17 @@ function decodeBase64(str) { | |
} | ||
|
||
export function allowCrossDomain(req, res, next) { | ||
const config = Config.get( | ||
req.get('X-Parse-Application-Id', getMountForRequest(req)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm making an assumption here that |
||
); | ||
let allowHeaders = | ||
'X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, Content-Type, Pragma, Cache-Control'; | ||
if (config && config.allowHeaders) { | ||
allowHeaders += `, ${config.allowHeaders.join(', ')}`; | ||
} | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); | ||
res.header( | ||
'Access-Control-Allow-Headers', | ||
'X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, Content-Type, Pragma, Cache-Control' | ||
); | ||
res.header('Access-Control-Allow-Headers', allowHeaders); | ||
res.header( | ||
'Access-Control-Expose-Headers', | ||
'X-Parse-Job-Status-Id, X-Parse-Push-Status-Id' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what happened here - maybe the pre-commit ran a formatter through it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it’s prettier