In preparation of upcoming work to support namespaces for /mobify routes, we are consolidating the places where /mobify routes are hard coded in the monorepo. This will enable us to make concise changes in the future.
Change Summary:
There is a new ssr-namespace-paths.js file in pwa-kit-runtime where /mobify paths are defined. All other packages, with the exception of commerce-sdk-react, will read the /mobify paths from this location.
commerce-sdk-react defines /mobify paths inside a single constants file
The hard coded reference to /mobify/bundle/development in webpack config has been removed. Instead, the publicPath used by HMR is defined dynamically via the __webpack_public_path__ global variable.
Testing the changes:
Start the app. Verify calls to /mobify/proxy/* or /mobify/bundle/development or /mobify/ping are all working
Try changing the value of __webpack_public_path__ global variable to something other than /mobify/bundle/development. Verify that this change is applied (when navigating between pages, you'll see that instead of loading the page, you'll see assets fail to load and the system will probably think you are in offline mode).
Run the tests - see that they are all passing
Change the namespace (ie. return something other than an empty string from getNamespace() and add a namespace to config.app.commerceAPI.proxyPath). See that everything works (only applies locally - this will not work on MRT without some changes on the MRT end)
Note:
I left some hard code /mobify paths in tests (usually inside request.get or expects or . I think in those locations it makes sense as we are directly testing on specific urls.
We do not need to provide the namespace into commerce-sdk-react. The storefront preview URLs are directed toward Runtime Admin and not the project environment, while SCAPI urls will receive the namespace via authConfig.proxy without us needing to make any changes outside of the config file.
Next steps:
There will be a subsequent PR to implement the getNamespace() function introduced in this PR. For now, getNamespace returns a blank string, which results in all /mobify routes still applying to root (unchanged from existing behaviour).
Going a bit into what this future PR might look like:
The namespace is likely to be defined in the config files via a property or a function.
By allowing the namespace to be a function, we can do something like the following inside a .js config file
This allows projects to define how they want to set the namespace without config.app details bleeding into pwa-kit-runtime. Thanks @bendvc for the suggestion on this!
In preparation of upcoming work to support namespaces for /mobify routes, we are consolidating the places where
/mobify
routes are hard coded in the monorepo. This will enable us to make concise changes in the future.Change Summary:
ssr-namespace-paths.js
file in pwa-kit-runtime where/mobify
paths are defined. All other packages, with the exception ofcommerce-sdk-react
, will read the/mobify
paths from this location.commerce-sdk-react
defines/mobify
paths inside a single constants file/mobify/bundle/development
in webpack config has been removed. Instead, the publicPath used by HMR is defined dynamically via the__webpack_public_path__
global variable.Testing the changes:
/mobify/proxy/*
or/mobify/bundle/development
or/mobify/ping
are all working__webpack_public_path__
global variable to something other than/mobify/bundle/development
. Verify that this change is applied (when navigating between pages, you'll see that instead of loading the page, you'll see assets fail to load and the system will probably think you are in offline mode).Note:
request.get
orexpects
or . I think in those locations it makes sense as we are directly testing on specific urls.Next steps: There will be a subsequent PR to implement the
getNamespace()
function introduced in this PR. For now, getNamespace returns a blank string, which results in all /mobify routes still applying to root (unchanged from existing behaviour).Going a bit into what this future PR might look like:
The namespace is likely to be defined in the config files via a property or a function. By allowing the namespace to be a function, we can do something like the following inside a .js config file
This allows projects to define how they want to set the namespace without config.app details bleeding into pwa-kit-runtime. Thanks @bendvc for the suggestion on this!