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

req.headers is undefined #1461

Closed
nirco123 opened this issue Apr 12, 2016 · 14 comments
Closed

req.headers is undefined #1461

nirco123 opened this issue Apr 12, 2016 · 14 comments
Assignees
Labels
type:feature New feature or improvement of existing feature

Comments

@nirco123
Copy link

Hi All,

Any reason why the req.headers is undefined, we would love to get the request IP and it seems impossible without the headers, I tried search the code and the headers are been overwrite, any specific reason for that?

Thanks.

@steven-supersolid
Copy link
Contributor

Assuming you mean in Cloud Code - this is the case on Parse.com but it is a bit limiting, e.g. we currently send the user agent information as part of a request as it is unavailable in the header.

The request object is not a node request object but Parse.Cloud.FunctionRequest
https://parse.com/docs/js/api/classes/Parse.Cloud.html#methods_define
I'd also like to know the reasoning behind this.

@nirco123
Copy link
Author

Yes, but since we are not on Parse.com hosting any more im trying to understand if there is any reason not using headers in the request .

@andyburgess1978
Copy link

I've anted to do something similar for ages, but until the parse server came along there wasn't a way to do it.
I haven't been able to get the headers in the cloud/main.js file so I've added routes that handle the IP detection and then forward that on to the cloud code using Parse.Cloud.run calling the cloud function.

app.post('/push', function(req, res) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
var data = {ips:ip};
Parse.Cloud.run('functionname', data, {
        success: function(response) {
          res.json({success: true, result:response});
        },
        error: function(error) {
          res.json({success: false, error:error});
        }
      });
}

@drew-gross
Copy link
Contributor

We didn't do this because we were aiming for compatibility with Parse.com. It seems like there is interest, though, and I don't see any reason not to add it.

@tarekskr
Copy link

Any updates on this? I think it's really vital to allow access to the request's headers from Cloud Code.

@ritterb82
Copy link

+1

@greggmojica
Copy link

+1

@tarekskr
Copy link

@greggmojica this has already been implemented 👍

@greggmojica
Copy link

@tarekskr I actually just saw that. My bad. Thanks!!

@crifkin
Copy link

crifkin commented Apr 6, 2017

@tarekskr the fix posted for #1461 doesn't appear to be true for Triggers. I see the code that adds this for Functions, but the method that headers would be injected for Triggers (before/afterSave, etc) is much more involved and I've spent several hours digging through code to try to find the place to put this in, so if you see a clear path, please provide guidance or help. thx.

@flovilmart
Copy link
Contributor

@crifkin sorry for the late response.

Yes it needs more work to be able to forward the request headers to the hooks.

I've prioritized it and we should be able to do something for that.

@flovilmart flovilmart reopened this May 6, 2017
@flovilmart flovilmart self-assigned this May 6, 2017
@miguel-s
Copy link
Contributor

@flovilmart I can take this issue, we have a working solution on our local branch and wouldn't take too long to create a pull request

@flovilmart
Copy link
Contributor

@miguel-s feel free to do so! I’ll review the Pr!

@flovilmart
Copy link
Contributor

Closing as PR is merged stay tuned for next release

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests