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

RFC: Move REST route recognition after routing resolves #130

Open
wants to merge 3 commits into
base: 4.6
Choose a base branch
from

Conversation

Steveb-p
Copy link
Contributor

🎫 Issue N/A

Description:

This PR adds a secondary check for REST API route after routing has been resolved.

This allows routes like /admin/api/ibexa/v2 to work.

Note

I removed the original method completely (onKernelRequest) and REST API remained functional.

For QA:

Documentation:

Copy link

sonarcloud bot commented Aug 30, 2024

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a bit confusing. We have X-Siteaccess header. While I get it's not working as expected, is there a possibility to fix that?
Second thing, so now we execute the same check twice in onKernelRequest and addAttributeForIbexaRestRoute. If we go with that solution can we keep just one method?

src/bundle/EventListener/RequestListener.php Show resolved Hide resolved
@Steveb-p
Copy link
Contributor Author

It could be a bit confusing. We have X-Siteaccess header. While I get it's not working as expected, is there a possibility to fix that?

It is working as expected.

All this does is expose REST routes under site-access aware prefixes, and results in both methods of switching to a different site-access to work.

(X-Siteaccess header takes priority afaik, but haven't checked)

Second thing, so now we execute the same check twice in onKernelRequest and addAttributeForIbexaRestRoute. If we go with that solution can we keep just one method?

Currently yes.

There is an argument to be made to keep the old method still executing since it is "almost" a contract. There might be packages or developers that rely on a particular order of event listeners.

Copy link
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate a bit on the origins of this change? I don't fully get the necessity of it.

@Steveb-p
Copy link
Contributor Author

Steveb-p commented Sep 2, 2024

Could you please elaborate a bit on the origins of this change? I don't fully get the necessity of it.

Sure.

Our frontend is using - or rather, would like to use - Routing.generate(<route>) on the frontend side (javascript), coming from FOS Routing bundle.

However, route generated there uses /admin prefix when generated from the admin UI. This makes that routing generation unusable, as our REST API does not respect site access prefixes. They need to hardcode REST routes.
The router does match the REST API route, but our view object dispatchers (which are a Symfony concept) do not work, because REST route recognition (putting is_rest_request attribute) is done before the information about semanticPathinfo is put into the Request.

So my suggestion is: move REST route recognition later down in the event chain. That way we will have access to the "actual" route, with site access prefix stripped. I've done basic checks and REST works properly still when this is moved into lower priority - but I've left the original recognition too, because there might be code that relies on it being checked early.

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. But in 5.0 let's get rid of the extra event.

@alongosz alongosz requested a review from a team September 4, 2024 08:08
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

Successfully merging this pull request may close these issues.

4 participants