-
-
Notifications
You must be signed in to change notification settings - Fork 201
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
redirectTo not working, Throwing Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client #529
Comments
@jaredpalmer If someone can look into please :) |
@qualwebs This is a bug indeed. if your code return // your server.js in src
server
.disable('x-powered-by')
.use(express.static(process.env.RAZZLE_PUBLIC_DIR))
.get('/*', async (req, res) => {
try {
const html = await render({
req,
res,
routes,
assets,
chunks,
});
if(html){ // add a judgement here
res.send(html);
}
} catch (error) {
console.error(error);
res.json({ message: error.message, stack: error.stack });
}
}); |
We ended up using a very similar solution to what @blinkcat posted here. But instead of if (res.statusCode == '302' || res.statusCode == '301') {
return;
}
res.send(html); I'm using I think in our case html was still getting a value, so that's why we went this route. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
馃悰 Bug report
The issue with redirection inside getInitialProps method
Current Behavior
I'm using AfterJS with razzle, Using a class component, and trying to validate the authorization inside getInitialProps method as suggested in the example of afterJs GitHub readme.
Here is the code sample
Expected behavior
It should redirect to login page if API returns 401 status code, Instead of throwing error Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Reproducible example
Suggested solution(s)
Additional context
Your environment
LOCAL
The text was updated successfully, but these errors were encountered: