Skip to content

Commit

Permalink
Tidy checks for redirect status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed May 14, 2024
1 parent 3a300e4 commit 8fdab9f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/4834.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return a redirect response from Volto server-side rendering if the API request was redirected. @JeffersonBledsoe @mamico
1 change: 0 additions & 1 deletion packages/volto/news/4834.feature

This file was deleted.

15 changes: 4 additions & 11 deletions packages/volto/src/components/theme/View/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,10 @@ class View extends Component {
*/
render() {
const { views } = config;
const status = __SERVER__
? this.props.error?.status
: this.props.error?.code;
// Checking to see if it's a 3XX HTTP status code. error.status only works on the server
if (status?.toString()?.[0] === '3') {
const redirectUrl = __SERVER__
? this.props.error.response.headers.location
: this.props.error.url;
let redirect = flattenToAppURL(redirectUrl);
// We can hit situations where we end up being redirected to an api route. We don't want that so lets remove ++api++.
redirect = redirect.replace('/++api++', '');
if ([301, 302].includes(this.props.error?.code)) {
const redirect = flattenToAppURL(this.props.error.url)
.split('?')[0]
.replace('/++api++', '');
return <Redirect to={`${redirect}${this.props.location.search}`} />;
} else if (this.props.error && !this.props.connectionRefused) {
let FoundView;
Expand Down
2 changes: 1 addition & 1 deletion packages/volto/src/helpers/Api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Api {
});
}

if (err?.status[0] === 3) {
if ([301, 302].includes(err?.status)) {
return reject({
code: err.status,
url: err.response.headers.location,
Expand Down

0 comments on commit 8fdab9f

Please sign in to comment.