TYPO3-Headless / headless

TYPO3 Headless JSON API providing content for PWA application (e.g. javaScript apps like nuxt-typo3)
https://t3headless.io
GNU General Public License v2.0
159 stars 60 forks source link

`frontendBase` ignored in SiteLanguages #674

Closed schloram closed 11 months ago

schloram commented 11 months ago

Describe the bug I'm not sure if I'm doing something wrong or misunderstanding the concept of the frontendUrl config but I can't really figure out how it should work. For me it looks like as if the frontendBase config inside languages does not really work. Or at least for the PreviewUri functionality.

To Reproduce My SiteConfig (for now please only pay attention to the 'applicationContext == "Development"' variant):

base: /
frontendBase: 'https://production-frontend.de'
baseVariants:
  -
    base: 'https://content-service.ddev.site'
    frontendBase: 'https://de.frontend.ddev.site'
    condition: 'applicationContext == "Development"'
headless: true
languages:
  -
    title: de_DE
    enabled: true
    languageId: 0
    base: /de/
    frontendBase: /
    locale: de_DE
    navigationTitle: Deutsch
    flag: de
    hreflang: ''
    websiteTitle: ''
    baseVariants:
      -
        base: /de/
        frontendBase: /
        condition: 'applicationContext == "Development"'
  -
    title: de_AT
    enabled: true
    locale: de_AT
    hreflang: ''
    base: /at/
    frontendBase: 'https://production-frontend.at'
    websiteTitle: ''
    navigationTitle: Österreichisch
    fallbackType: strict
    fallbacks: ''
    flag: at
    languageId: 1
    baseVariants:
      -
        base: /at/
        frontendBase: 'https://at.frontend.ddev.site'
        condition: 'applicationContext == "Development"'
rootPageId: 1
websiteTitle: ''

Expected behavior I expect my urls to be as follows:

When clicking the "Preview webpage" icon (image) on an translated page I expect it to go to the url https://at.frontend.ddev.site. Instead I'm being redirected to https://content-service.ddev.site/at/

Am I misunderstanding the use-case of frontendUrl in general? Plus: Why isn't there a frontenUrl field in every SiteLanguage? That's why the manually added config always gets removed after saving vie backend module.

Screenshots If applicable, add screenshots to help explain your problem.

TYPO3 version and TYPO3 Headless version TYPO3: 12.4.7 Headless: 4.2.2 (with flag headless.frontendUrls set to true)

Additional context Add any other information related to the problem here.

schloram commented 11 months ago

After investigating a little further I think one problem might be that the $this->headlessMode->isEnabled() check inside the UrlUtility always returns false because the backend request does never contain the attribute headless.

twoldanski commented 11 months ago

Hi @schloram, thank you for reporting. FYI Flag headless.frontendUrls in version 4.x is dropped. Since 4.2 you need only set headless flag in site configuration and configure frontendBase urls on site and/or in site language.

Please test with this patch https://github.com/TYPO3-Headless/headless/pull/675

schloram commented 11 months ago

Hi @twoldanski ,

wow, what an incredible response time! And thanks for the hint regarding the flag. ❤️

Okay, the fix solves the initial problem. But somehow it still behaves odd with the above config.

Given the above config I want to have the TYPO3 accessible with only one domain and the languages are accessible via path (e.g https://content-service.ddev.site/de/ and https://content-service.ddev.site/at/) The frontend however should be accessible via two separate domains (e.g https://de.frontend.ddev.site and https://at.frontend.ddev.site)

Now when I preview the AT page from within the backend it redirects to https://at.frontend.ddev.site/at/ instead of only https://at.frontend.ddev.site. It uses kind of a combination of both: the base and the frontenBase. I located the source here where $frontBase and $targetUri are being merged. Not sure how to solve this. 🤔

twoldanski commented 11 months ago

Hi @schloram, this not exactly possible you would like to do. OK, you can do it, but you have to override how TYPO3 resolves paths/languages etc. In headless we only override domains because we have to apps - backend (T3) and FE app, but nothing more. We try to do not change how TYPO3 works in major way. You could write some custom code to handle your case.

schloram commented 11 months ago

@twoldanski Thanks for your response!

Not sure if I get your right but we also have only have one FE and one BE. The only requirement that could be considered remotely special here is that the domains/urls don't match: The frontend should be accessible via separate TLDs (like https://my-site.de and https://my-site.at) while the backend (JSON) will be called from the frontend with one domain but a path per language (e.g https://api.my-site.com/de/ and https://api.my-site.com/at/).

I mean if I'm able to define a frontendBase per language it shouldn't really be extended/merged with the language path from the base. To my understanding It should be independent.

A more detailed example: With the above config right now when I'm on the page "My Subpage" in the default language which slug is /my-parent/my-subpage and I want to preview that page it always links to https://de.frontend.ddev.site/de/my-parent/my-subpage. But since I defined a separate frontendBase I'm expecting it to link to https://de.frontend.ddev.site/my-parent/my-subpage because the /de/ part inside the actual url is part of the base and not frontendBase.

Another question: Why isn't there a frontendBase field per language if the extension is already parsing the (manually added) frontendBase inside languages?