Skip to content
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

Add CORS headers to microservice #17

Merged
merged 3 commits into from
Jan 12, 2017
Merged

Conversation

juandjara
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Jan 11, 2017

Current coverage is 93.24% (diff: 100%)

Merging #17 into master will increase coverage by 0.09%

@@             master        #17   diff @@
==========================================
  Files             4          4          
  Lines            73         74     +1   
  Methods          13         13          
  Messages          0          0          
  Branches         14         14          
==========================================
+ Hits             68         69     +1   
  Misses            5          5          
  Partials          0          0          

Powered by Codecov. Last update 6aebd25...9c7e326

@relekang
Copy link
Member

Maybe this could be configurable? Would be nice to set a list of the domains it is used from.

@mxstbr
Copy link
Member

mxstbr commented Jan 12, 2017

Why would somebody restrict the domains this can be used from, what's the use case?

Thanks for the PR @juandjara, this is a great addition!

@relekang
Copy link
Member

Filtering out local calls from development of a website using this, but this might not be the best way to do it 😛

@mxstbr
Copy link
Member

mxstbr commented Jan 12, 2017

See #11, I think this should be fine?

@@ -6,6 +6,8 @@ const { pushView } = require('./utils')

module.exports = async function (req, res) {
const { pathname, query } = url.parse(req.url, /* parseQueryString */ true)
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
Copy link
Member

@mxstbr mxstbr Jan 12, 2017

Choose a reason for hiding this comment

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

If I understand this right (I might have this totally wrong though, not an expert so correct me), the Access-Control-Allow-Headers header tells the client which headers it can send and the server will respect, right? But we don't respect Content-Type nor Accept at all, we always just send JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had not thought of that. I just copied this from another project, I tried it and it worked. I know at least the Origin header is necessary, not sure about X-Requested-With

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need X-Requested-With, at least according to this SO answer? https://stackoverflow.com/questions/17478731/whats-the-point-of-the-x-requested-with-header#22533680

Am I reading that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems right. I wil check it later today and update this PR

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for digging into this, appreciated! Definitely want to get this right 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so I tested and found that no headers are actually necessary so I'm reverting last commit.

This reverts commit 04f5916.
@mxstbr
Copy link
Member

mxstbr commented Jan 12, 2017

LGTM, thanks so much!

@mxstbr mxstbr merged commit 5ea0c93 into micro-analytics:master Jan 12, 2017
@joshwcomeau joshwcomeau mentioned this pull request Jan 28, 2018
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.

4 participants