vuestorefront / shopware-pwa

Shopware PWA for eCommerce. Headless storefront solution for Shopware 6, which communicates through the SalesChannel-API. Always Open Source, MIT license. Made with :blue_heart: by shopware AG & Vue Storefront.
https://frontends.shopware.com
MIT License
345 stars 103 forks source link

[BUG] Domains are not fetched from Shopware instance #1343

Closed willopez closed 3 years ago

willopez commented 3 years ago

Describe the bug

I followed the instructions on installing the pwa canary version and I get the following error when executing this command: npx @shopware-pwa/cli@canary init

Error:

Please provide username and password for plugins authentication. You can leave the fields empty if connecting to demo instance or if you don't need plugins :)
✔ Shopware admin username: · admin
✔ Shopware admin password: · ********
✔ Do you want to allow dev mode for slots? (Don't use for production!) (y/N) · false
UNEXPECTED ERROR [object Object]
✔ Generating plugins files
Shopware languages refreshed
Plugins generated
CMS prepared
Shopware languages refreshed

Not sure what the UNEXPECTED ERROR [object Object] is, but the end results is that the domains.json is an empty object and the languages.json seems to be populated correctly:

{
  "en-US": {
    "id": "2fbb5fe2e29a4d70aa5854ce7ce3e20b",
    "code": "en-US",
    "name": "English"
  },
  "de-DE": {
    "id": "48748d8b982b4224925959b62a473b6d",
    "code": "de-DE",
    "name": "German"
  }

The app fails to start.

In the Shopware instance access logs I see the following 500 error

- [04/Feb/2021:17:23:56 +0000] "GET //pwa/866f04b9e45b1a938800b6f730fe1db5.json HTTP/1.1" 500 843 "-" "axios/0.21.1"
shopware_1  | 172.18.0.2 - - [04/Feb/2021:17:23:56 +0000] "GET /store-api/v3/language HTTP/1.1" 200 2091 "-" "axios/0.21.1"

Additional context

Using: shopware-pwa/shopware-pwa 2.0 Shopware 6.3.5.0

elkmod commented 3 years ago

@willopez thanks for reporting! Could you check whether shopwareEndpoint in your shopware-pwa.config.js contains a trailing /? If so, try removing it and re-initialising.

Dom

elkmod commented 3 years ago

Hi @willopez!

First of all - I am able to run a local version of shopware-pwa with your API, so it is working perfectly fine.

Let my try to clarify:

shopwareEndpoint is the URL which all API requests paths are built made relative to. It has nothing to with the domain configuration of your sales channel. A good indication is the URL of your admin panel. In your case it is located at https://pwa-api.willopez.com/admin. Hence, the root path of your Shopware instance - the shopwareEndpoint is https://pwa-api.willopez.com (without a trailing /)

shopwareAccessToken is used to identify the sales channel for your PWA

pwaHost is the URL relative to which you want your frontend application to do the routing. It is tied to the domain configuration of your sales channel. If your sales channel has only a single configured domain (which CAN be the same as shopwareEndpoint, but by no means has to), set pwaHost to the same value (again without trailing /).

If however, you're going to configure multiple domains (which in Shopware wording can also mean suffixes rather than just domains) like

they would share the common pwaHost which in that case would be https://pwa-frontend.willopez.com. The shopwareEndpoint in that case would remain the same as before.

Try the following configuration for shopware-pwa.config.js, it worked for me

module.exports = {
  shopwareEndpoint: "https://pwa-api.willopez.com",
  shopwareAccessToken: "SWSCYTV6VLPJQNVUCENOQNO5QW",
  pwaHost: "https://pwa-api.willopez.com",
};

PS: You should be able to join the slack channel without an explicit invitation (we will remove the old one from the README) - VSF Slack Channel

willopez commented 3 years ago

@elkmod Got it, I was just confused as to the mapping of the domains, everything is working now. Thanks! and great work on this project.