Closed (fixed)
Project:
Decoupled Router
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Aug 2025 at 10:00 UTC
Updated:
22 Sep 2025 at 15:44 UTC
Jump to comment: Most recent
Some sites want to have relative URLs in the responses and not absolute. Make this configurable.
I propose we do not add a form for configuring this but add docs to the readme to config with Drush.
New parameters for \Drupal\decoupled_router\EventSubscriber\RouterPathTranslatorSubscriber::resolvedPathIsHomePath() to ensure cacheability info is correct.
New decoupled_router.settings configuration.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
alexpottComment #4
krystalcode commentedThis may be a matter of preference or semantics. The same way that within Drupal we don't define internal redirects using the full URL including the scheme/hostname etc., we just use the path, similarly on the client side - for example on Next server - you define a redirect like
NextResponse.redirect(new URL('/my-content-url', request.url)). It does not make much sense to sayNextResponse.redirect(new URL('https://www.example.com/my-content-url', request.url))if you are already on that domain. That said, passing the full URL would work as well. I don't know Next well enough to say whether internally there's any functional or performance-related difference.Also, the backend resolves the path based on its own URL. That is, the resolved URL would be
https://api.example.com/my-content-url, while what we need ishttps://www.example.com/my-content-url. This means that the frontend would have to extract the path, and that's unnecessary.Semantically - together with the
isRedirectproperty, this basically says that "you're staying on the same site but you're redirected to another page". Otherwise, if the frontend just wanted the final internal path it would either have to extract it from theresolvedproperty (not that it's a big deal), or from the last item of theredirectarray which is unnecessary code for the frontend to handle. The former option i.e.resolvedproperty actually - and if I remember correctly - would not properly carry over query parameters and fragments, while - together with some other fixes on this module - they would be carried over in theredirectarray.Together with some other changes to carry over query parameters and fragments in the
resolvedthat I have not added here on this module, all that the frontend has to do is to grab that path. For the bigger context that may be useful when reviewing other issues that I opened in this module, here is what we were trying to achieve.This came up as part of a bigger effort to make things as simple as possible for the frontend. We found that a decoupled frontend would have to write quite a bit of code to handle different cases e.g. path given as a URL alias, path given as the internal path, path or URL alias that gets redirected, redirects to internal vs to external URLs, issues with carrying over query parameters from the given path and from any applicable redirects, some special handling for the home page that can be found as
/or as internal path or as URL alias of the node etc.To have logic for handling all these different cases in the frontend ended up being time consuming and error prone i.e. all sorts of bugs were found, fixing something only to break something else etc.
At the end, here is the final structure that we ended up with. We found that this structure minimizes the logic that has to be done in the frontend on all cases. Example response:
Comment #5
alexpottOkay so resolved and redirect urls will obey the absolute setting but the urls inside jsonapi and entity will remain absolute. The one that is interesting is the canonical URL. I would guess that the front end think it exposes the canonical URL for the entity and not the backend.
Comment #6
alexpottThe current MR reflects what is wanted by #4.
Comment #7
alexpottComment #8
alexpottComment #9
mglamanTried to rebase via the UI and it failed on conflicts, otherwise good to go
Comment #10
alexpottI'll update this once https://www.drupal.org/project/decoupled_router/issues/3543594 lands as that one conflicts with this one.
Comment #11
alexpottComment #12
alexpottFixed up the MR after the latest merges
Comment #13
mglamanThanks! Merge train ahead