yireo-training / vsf1-local-webpack

Optimized Webpack configuration for Vue Storefront 1 development
11 stars 3 forks source link

Bug - Multistore not honoured #3

Open slri opened 3 years ago

slri commented 3 years ago

Heyo!

We've set this up as the documentation suggests. One major issue we're having is that the rules about storeViews aren't being honoured. We've implemented this to run in our docker infrastructure, added some extra steps such as allowedHosts, changed server port and host. However, the hosts aren't being interpreted as they should be.

How to reproduce:

  1. Replace devServer definition with this:
    devServer: {
    historyApiFallback: {
      rewrites: [{ from: /./, to: "/index.html" }]
    },
    publicPath: "/",
    open: false,
    writeToDisk: true,
    watchContentBase: true,
    contentBasePublicPath: "/assets",
    host: 0.0.0.0,
    port: 8080,
    allowedHosts: [
      "example.com.local",
      "example.co.uk.local"
    ],
    contentBase: [path.join(__dirname, "src/themes/default/assets")]
    },
  2. Merge the following config with vue-storefrontRoot/core/build/config.json:
    "server": {
    "host": "0.0.0.0",
    "port": "8080"
    },
    "storeViews": {
    "multistore": true,
    "en": {
      "storeCode": "en",
      "storeId": 1,
      "name": "example.com",
      "url": "example.com.local",
      "appendStoreCode": false,
      "elasticsearch": {
        "host": "/api/catalog",
        "index": "vue_storefront_catalog_en"
      },
      "i18n": {
        "fullCountryName": "International",
        "fullLanguageName": "English",
        "defaultLanguage": "EN",
        "defaultCountry": "GB",
        "defaultLocale": "en-GB",
        "currencyCode": "EUR",
        "currencySign": "€",
        "dateFormat": "HH:mm D-M-YYYY"
      },
      "seo": { "defaultTitle": "example.com" }
    },
    "gb": {
      "storeCode": "gb",
      "storeId": 2,
      "name": "example.co.uk",
      "url": "example.co.uk.local",
      "appendStoreCode": false,
      "elasticsearch": {
        "host": "/api/catalog",
        "index": "vue_storefront_catalog_gb"
      },
      "i18n": {
        "fullCountryName": "International",
        "fullLanguageName": "English",
        "defaultLanguage": "EN",
        "defaultCountry": "GB",
        "defaultLocale": "en-GB",
        "currencyCode": "EUR",
        "currencySign": "€",
        "dateFormat": "HH:mm D-M-YYYY"
      },
      "seo": { "defaultTitle": "example.co.uk" }
    }
    }
  3. Visit the exposed app with host set to either example.com.local or example.co.uk.local

The storeView-specific settings (such as elasticsearch) won't be honoured. Any idea on what could be the issue?

Thanks in advance!

slri commented 3 years ago

Found the source of the storeView issue. It's in https://github.com/vuestorefront/vue-storefront/blob/master/core/client-entry.ts#L22 So the issue is that the server will be pulling the storeCode based on host requested. When we're running without the server part to it, storeCode will always be nothing, preventing the app from pulling the correct data from config.

Will make a PR to add client-entry.ts to the mix in the event that the user requires multistore functionality.