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

wrong redirects when using Volto ? #152

Closed
mamico opened this issue May 30, 2023 · 4 comments
Closed

wrong redirects when using Volto ? #152

mamico opened this issue May 30, 2023 · 4 comments

Comments

@mamico
Copy link
Member

mamico commented May 30, 2023

While working on pull requests plone/volto#4821 and plone/volto#4826, I encountered the following anomalous behavior:

The page "foo" was renamed to "bar".
Volto published with seamless mode.
Inside a page, there is a REST API call, for example, a GET_CONTENT request to "/foo".
The call is transformed into a backend request like this (managed by superagent or the browser):

wget http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot/foo -S --header="Accept: application/json"

The backend responds with:

HTTP/1.1 302 Found
Content-Type: application/json
Location: http://localhost:3000/bar

At this point, superagent (or the browser) autonomously follows the redirect and makes a request that returns an HTML response, which is then ignored and replaced with a 301 exception here:

https://github.com/plone/volto/blob/9c5b4ccf94281e2849ca9b66e74cafe7f5ef87cb/src/helpers/Api/Api.js#L102

However, in a block, this exception might not be correctly handled, and actually would probably not be the most appropriate way to handle it.

Personally, I see two approaches to address this issue (the first being my preferred option):

  1. Handle the superagent REST redirects to rewrite the redirect location.
  2. Modify plone.rest to bring back ++api++ on the right side of the Virtual Host Monster (VHM), similar to how it was done with the legacy traverser.
@djay
Copy link
Member

djay commented May 30, 2023

@mamico This is the same problem outlined in plone/volto#4800. I think (2) is the solution. api redirect should include ++api++ in it even with VHM.

@mamico
Copy link
Member Author

mamico commented May 31, 2023

@mamico This is the same problem outlined in plone/volto#4800. I think (2) is the solution. api redirect should include ++api++ in it even with VHM.

Yes. Exactly the same. Thanks

But I do not know whether the solution could also be, simply: change VHM currently used in Volto (as in documentation and as default for development)

http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot/foo

to

http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/VirtualHostRoot/++api++/foo

\cc @sneridagh

@djay
Copy link
Member

djay commented Jun 2, 2023

@mamico How you do your VHM is up to the user. We use the internal VHM rules and this bug is breaking volto for us.
So the fix should be that regardless of how you do VHM, an api call should redirect to an api call.

We have already done a PR on volto to fix the fact that volto relies on this bug + the specific VHM config to work currently - plone/volto#4834

@davisagli
Copy link
Member

This was fixed a while back in plone/volto#4854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants