Problem/Motivation

The sub-directory/folder issue of Drupal base path and Drupal root path

Steps to reproduce

Given that the Project Browser module was installed on the standard recommended Drupal 9 build with the following directory physical path "/var/www/html/dev/drupal9project_browser"
But no direct domain to point at the folder "/var/www/html/dev/drupal9project_browser/web"
When navigating to "http://localhost/dev/drupal9project_browser/web/admin/modules/browse" URL
No data is loading
And that indicates more issues with Drupal routes + Svelte routes
private and public permissions to access the Svelte app Routes
And when the site is working with another languages as the default language with a sub path

Proposed resolution

Pass the site:origin-url not the site:url to the Svelte App script
Add a session key for Svelte App routes

The Origin URL: Origin URL (scheme and HTTP host) of the site. No language prefix.

          // Until #1088112: Introduce a token to get site's base URL is
          // committed,
          // https://www.drupal.org/project/drupal/issues/1088112
          // let's use a custom token. Let's call it: [site:origin-url].
          // No language prefix in the url.
          // -----------------------------------------------------------------
          /** @var \Symfony\Component\HttpFoundation\Request $origin_url */
          $origin_url = \Drupal::request()->getSchemeAndHttpHost() . \Drupal::request()->getBaseUrl();

origin_url could be used in the Svelte App or any other script.
Not to fall into issues like #1088112: Introduce a token to get site's base URL

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Pass the site:origin-url not the site:url to the Svelte App script
  • ✅ Testing to ensure no regression
  • ❌ Automated unit/functional testing coverage
  • ❌ Developer Documentation support on feature change/addition
  • ❌ User Guide Documentation support on feature change/addition
  • ❌ Code review from core team member
  • ❌ Full testing and approval
  • ❌ Credit contributors
  • ❌ Review
  • ❌ Release

User interface changes

  • None

API changes

  • APIs for Apps will be under the Drupal Routing, session, and permission control

Data model changes

  • None
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RajabNatshah created an issue. See original summary.

Rajab Natshah’s picture

Issue summary: View changes
Rajab Natshah’s picture

Rajab Natshah’s picture

Issue summary: View changes
Rajab Natshah’s picture

Assigned: Rajab Natshah » Unassigned
Rajab Natshah’s picture

Issue summary: View changes
Rajab Natshah’s picture

Issue summary: View changes
Rajab Natshah’s picture

FileSize
407.82 KB

This patch is passing origin_url to the drupalSettings.project_browser
So it could be used as drupalSettings.project_browser.origin_url in routes and assets

Example with routes:

  const res = await fetch(drupalSettings.project_browser.origin_url + "/drupal-org-proxy/project");

Example with assets:

<a href="https://www.drupal.org/security-advisory-policy" target="_blank" rel="noreferrer"><span class="security-covered" title="Covered by Drupal Security Team"><img src="{drupalSettings.project_browser.origin_url}/{drupalSettings.project_browser.module_path}/images/shield-icon-black.svg" /></span></a>

It could be that it fixes the

// todo Make this URL dynamic. It would work to simply change this to
// "/drupal-org-proxy/project" for when the Svelete JS is loaded within a Drupal page,
// but that would not work during development when viewing the Svelte app on http://localhost:5000/.

Named the passed value as origin_url, which for sure can be changed.
The Origin URL: Origin URL (scheme and HTTP host) of the site. No language prefix.

Rajab Natshah’s picture

Issue summary: View changes
Status: Active » Needs review
Rajab Natshah’s picture

Issue summary: View changes
Rajab Natshah’s picture

Title: Drupal routing and Svelte app routing » Fix Drupal routing and Svelte app routing
Rajab Natshah’s picture

  • Tested in single language site.
  • Tested in multilingual site, with a language selection using the URL is ON for languages.
  • Tested in sub-folder websites. No direct domain pointer to the site.
Rajab Natshah’s picture

Would you like to keep the origin_url name for the argument.
Thanks a lot :)
Learned new things to get to this point for this fix.

rlnorthcutt’s picture

This seems like a very clean solution overall.

One thing: the patch includes the Svelte bundle and output. This makes sense for the actual PR we need, but perhaps we should break Svelte related work into two patches? One for the component/code changes and one for the whole thing? I know it's a pain to take the extra step, but it will make it much simpler to review.

rlnorthcutt’s picture

Side note: perhaps we should file a core issue to see about getting something like "drupalSettings.origin_url" put in place. It seems like a really powerful and useful thing that core could provide for any JS tool.

Rajab Natshah’s picture

Thanks, Ron
I do agree with the drupalSettings.origin_url in core
#1088112: Introduce a token to get site's base URL
Hoping to be committed to the core. Or a new issue for the JS passing of new origin_url value.

About the Svelte bundle and output. Noted on that.
I'm still learning .. and thinking of ways to attach postcss and CSS files in .svelte files
or at least in the process of building.

chrisfromredfin’s picture

Is #3236846 a related issue to this? Can one be marked as a dupe of the other?

Rajab Natshah’s picture

Following up on #14
Having 2 new parted patches
project_browser-3227738-18.patch
project_browser--Svelte-bundle-and-output--3227738-18.patch

rlnorthcutt’s picture

@Chris - I think so? I asked on the other issue to see if they can test/confirm.

@Rajab - considering that there is a core issue open, perhaps we should contribute there and include the patch in our module composer file (that works, right?). That way we can contribute to the core patch we will ultimately want/need, and it looks like there are a few more edge cases noted there. Better coverage and attention there.

Plus, I may be able to get that on the radar of some core folks when we feel like it is ready for final review.

Rajab Natshah’s picture

Noted;
Following on that in the Drupal core issue
#1088112: Introduce a token to get site's base URL

Rajab Natshah’s picture

Not sure when #1088112: Introduce a token to get site's base URL will be committed to Drupal core
I recommend fixing this in the current working module.

Rajab Natshah’s picture

Assigned: Unassigned » Rajab Natshah
Status: Needs review » Active
Rajab Natshah’s picture

Rajab Natshah’s picture

Status: Active » Needs review
Rajab Natshah’s picture

Rajab Natshah’s picture

Status: Needs review » Active
Rajab Natshah’s picture

Assigned: Rajab Natshah » Unassigned
Status: Active » Needs review
FileSize
777.79 KB
6.43 KB
gaurav.kapoor’s picture

@RajabNatshah Thanks for providing the patch, the project browser wasn't working for me in the local but started working after applying the patch provided in #27.

Also, any reason of appending \Drupal::request()->getBaseUrl() in the line

+            'origin_url' => \Drupal::request()->getSchemeAndHttpHost() . \Drupal::request()->getBaseUrl(),

\Drupal::request()->getSchemeAndHttpHost() is returning the required base path which has to be added before URLs in the Svelte app. Will it needed for any particular kind of setup?

Rajab Natshah’s picture

This is for when the site is in http:// or https://
To work on the current configured hosting protocol settings

gaurav.kapoor’s picture

Status: Needs review » Reviewed & tested by the community

Ok. Cool. Tested #27 and it fixes timeout or no record issues resulting from wrong paths.

chrisfromredfin’s picture

Status: Reviewed & tested by the community » Fixed

pushed to 1.0.x! Thank you all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.