Skip to content

Commit

Permalink
Fix 301 and 302 redirects. (#5999)
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema authored May 3, 2024
1 parent ca286aa commit 0fbeea4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/5999.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 301 and 302 redirects. @robgietema
5 changes: 5 additions & 0 deletions packages/volto/src/components/theme/View/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class View extends Component {
if (this.props.error && this.props.error.code === 301) {
const redirect = flattenToAppURL(this.props.error.url).split('?')[0];
return <Redirect to={`${redirect}${this.props.location.search}`} />;
} else if (this.props.error && this.props.error.status === 302) {
const redirect = flattenToAppURL(
this.props.error.response.header.location,
).split('?')[0];
return <Redirect to={`${redirect}${this.props.location.search}`} />;
} else if (this.props.error && !this.props.connectionRefused) {
let FoundView;
if (this.props.error.status === undefined) {
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 @@ -54,7 +54,7 @@ class Api {
) => {
let request;
let promise = new Promise((resolve, reject) => {
request = superagent[method](formatUrl(path));
request = superagent[method](formatUrl(path)).redirects(0);

if (params) {
request.query(params);
Expand Down
14 changes: 8 additions & 6 deletions packages/volto/src/helpers/Api/Api.plone.rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Api from './Api';

jest.mock('superagent', () => ({
get: jest.fn((url) => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
redirects: jest.fn(() => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
})),
})),
}));

Expand Down
14 changes: 8 additions & 6 deletions packages/volto/src/helpers/Api/Api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Api from './Api';

jest.mock('superagent', () => ({
get: jest.fn((url) => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
redirects: jest.fn(() => ({
url,
query: jest.fn(),
set: jest.fn(),
type: jest.fn(),
send: jest.fn(),
end: jest.fn(),
})),
})),
}));

Expand Down

0 comments on commit 0fbeea4

Please sign in to comment.