-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Error: Can't set headers after they are sent. CORS #2448
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
Comments
Can you provide any additional information on what triggers this use error? Is there a particular endpoint you hit or action that you are taking when it happens? |
I also see this error on v2.2.17:
It happens if I run cloud code, I couldn't identify exactly where it is but it's related to the errorhandler in the cloud code |
The problem is not from parse server itself but how the express routes are configured. Some of your middlewares are run after parse has processed it's requests. Please check the order of your middlewares and also, consider excluding the parse route. Another option may be:
Again it depends of the middlewares you use, and how they are designed. Calling next() is part of express best practices, so I don't think we'look remove it. |
thanks @flovilmart - I also assume this is more an error on my/our end than a parse error, I'll investigate. however I never saw those errors before v2.2.13 |
That's normal that it didn't appear before as we added next() calls after error/responses so additionnal loggers/handlers can be called after parse-server responded |
I have been following this and #2362, I have not been able to reproduce any Header error unless I do something wrong inside the express side of things. E.g binding the parse app twice, or sending As I stated in the other issue the common places to look is your The order is very important to
|
See #2362 |
I don't think that this is the issue. I disabled cloud code, Open Parse Dashboard, voila! for each class in the schema I get the same error repeated!
So I don't think this is my cloud code issue and here is my server init
|
This is likely |
yes I tried to comment that line and also and also
as I thought maybe it cause the problem because I'm mounting in '/' but still see the error |
Given the stacktrace this is because your cors middleware is run AFTER parse-sever. But not inside parse-server |
what do you mean ? my index.js looks like this now
I still see the error |
I mean
|
I also remove |
What error? we don't have the cors module in parse-server, are you sure it's exactly the same stack trace? |
here is the other error coming from express
this is even after removing CORS completely |
So you you notice this is not the same stack trace therefore the same error? I'm not sure at that point why your express module would spit those errors. I tested with parse-server-example and didn't get that output either. What version of express are you running in your main package? |
Thanks.
|
use express 4.14.0 https://github.com/ParsePlatform/parse-server/blob/master/package.json#L28 as parse-server uses, it's untested with 4.2 which by the way is more than 2 years old... https://github.com/expressjs/express/tree/4.2.0 . |
Thanks a lot! this saved my life :) I also had to remove |
Wow, I've been watching this thread for ages stuck with the same issue, and it turns out the issue all along was the express version. I had based my original project off of parse-server-example which prior to March 16th had express ^4.2.x in the package.json. This was updated after that date to ^4.11.x. I had to make no code changes except change to 4.14.0 and it all works now. |
It stills happen although using express 4.14.0 using node 4.5
this happen when afterSave/BeforeSave trigger. with Node 6.4.0
In this function!
After I comment that line, it works |
@benishak Can you make a pull request that delete that line? |
This is how I solved it:
I have no idea why after parse-server handled the request it want to call "next()". Does it have anything to do with Cloud code? If that is the case, I guess parse-server is meant to be stand alone. It is not mean to be installed onto your node server. |
There is already an open PR to remove the next() calls |
@flovilmart Which PR? Do you have a link? |
Env
Parse Server 2.2.17
AWS CentOS NGINX
Problem
I'm getting this error in the console
after downgrading to version
2.2.16
. The error goes away!Reproduce
Upgrade to 2.2.17
The text was updated successfully, but these errors were encountered: