Fix Drupal routing and Svelte app routing
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3227738. -->
Reported by: [rajab natshah](https://www.drupal.org/user/1414312)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>The sub-directory/folder issue of Drupal base path and Drupal root path</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<blockquote><p>
Given that the <strong>Project Browser</strong> module was installed on the <strong>standard recommended Drupal 9</strong> build with the following directory physical path <strong><em>"/var/www/html/dev/drupal9project_browser"</em></strong><br>
But no direct domain to point at the folder <strong><em>"/var/www/html/dev/drupal9project_browser/web"</em></strong><br>
When navigating to <strong><em>"<a href="http://localhost/dev/drupal9project_browser/web/admin/modules/browse">http://localhost/dev/drupal9project_browser/web/admin/modules/browse</a>"</em></strong> URL<br>
No data is loading<br>
And that indicates more issues with Drupal routes + Svelte routes<br>
private and public permissions to access the Svelte app Routes<br>
And when the site is working with another languages as the default language with a sub path</p>
</blockquote>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Pass the <code>site:origin-url</code> not the <code>site:url</code> to the Svelte App script<br>
Add a session key for Svelte App routes</p>
<p>The <strong>Origin URL</strong>: Origin URL (scheme and HTTP host) of the site. <strong>No language prefix.</strong></p>
<pre> // Until #1088112: Introduce a token to get site's base URL is<br> // committed,<br> // https://www.drupal.org/project/drupal/issues/1088112<br> // let's use a custom token. Let's call it: [site:origin-url].<br> // No language prefix in the url.<br> // -----------------------------------------------------------------<br> /** @var \Symfony\Component\HttpFoundation\Request $origin_url */<br> $origin_url = \Drupal::request()->getSchemeAndHttpHost() . \Drupal::request()->getBaseUrl();</pre><p>origin_url could be used in the Svelte App or any other script.<br>
Not to fall into issues like <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/drupal/issues/1088112" title="Status: Closed (fixed)">#1088112: Introduce a token to get site's base URL</a></span></p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>✅ File an issue about this project</li>
<li>✅ Pass the <code>site:origin-url</code> not the <code>site:url</code> to the <strong>Svelte App</strong> script</li>
<li>✅ Testing to ensure no regression</li>
<li>❌ Automated unit/functional testing coverage</li>
<li>❌ Developer Documentation support on feature change/addition</li>
<li>❌ User Guide Documentation support on feature change/addition</li>
<li>❌ Code review from core team member</li>
<li>❌ Full testing and approval</li>
<li>❌ Credit contributors</li>
<li>❌ Review</li>
<li>❌ Release</li>
</ul>
<h3 id="summary-ui-changes">User interface changes</h3>
<ul>
<li>None</li>
</ul>
<h3 id="summary-api-changes">API changes</h3>
<ul>
<li>APIs for Apps will be under the Drupal Routing, session, and permission control </li>
</ul>
<h3 id="summary-data-model-changes">Data model changes</h3>
<ul>
<li>None</li>
</ul>
> Related issue: [Issue #1088112](https://www.drupal.org/node/1088112)
issue
GitLab AI Context
Project: project/project_browser
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/project_browser/-/raw/2.1.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/project_browser
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD