Repository: plone/Products.CMFPlone

Issue:
Merged bundles does not work when switching domains
Another issue I've encountered when using the merged bundle feature is that it includes generated requirejs configuration. Generated requirejs configuration includes a `baseUrl` setting which is specific to the url that you first created the site with.

Imagine you create the site, through a tunnel on localhost:8080, then switch the site over to production. The requirejs config has the baseUrl as `http://localhost:8080/Plone` and things start breaking.

\cc @ebrehault 



Discussion:
And do you think we could set `baseUrl` to `'/Plone'` instead of `'http://localhost:8080/Plone'` or does `require` really need a full url here?

An easy fix is to exclude this file from the merged bundles (so that will add another JS request when we load a Plone page, but at least it will work).

Or we just do something like `$('body').attr('data-portal-url') || '/Plone'`

I was also hit by this prob when I tried to upgrade a site some weeks ago. It worked without virtual hosting, but with nginx on the front, pointing to a virual host root, it didn't.

@thet fwiw, turning on dev mode and then off again in resource registries forces them to be re-cooked.

@thet you can also import the "Bundle combination" GenericSetup step

I did not know about the bundle combination setup step. sounds good!
unrelated - but IMO plone should withdraw old ++UNIQUE++ cachign urls and generate new ones on startup (that was also the behavior in Plone 4 and actually convenient). but that's unrelated.

related is: https://github.com/plone/Products.CMFPlone/issues/1433
this is the issue describing roughly what we encountered on a plone upgrade at the beginning of march.


Resolving patch:
diff --git a/Products/CMFPlone/controlpanel/browser/resourceregistry.py b/Products/CMFPlone/controlpanel/browser/resourceregistry.py
--- a/Products/CMFPlone/controlpanel/browser/resourceregistry.py
+++ b/Products/CMFPlone/controlpanel/browser/resourceregistry.py
@@ -287,7 +287,7 @@ def less_build_config(self):
         })
 
     def js_build_config(self):
-        (baseUrl, paths, shims) = self.get_requirejs_config()
+        (paths, shims) = self.get_requirejs_config()
         bundles = self.get_bundles()
         resources = self.get_resources()
 
diff --git a/Products/CMFPlone/resources/browser/configjs.py b/Products/CMFPlone/resources/browser/configjs.py
--- a/Products/CMFPlone/resources/browser/configjs.py
+++ b/Products/CMFPlone/resources/browser/configjs.py
@@ -4,12 +4,11 @@
 from Products.CMFPlone.interfaces import IResourceRegistry
 from Products.Five.browser import BrowserView
 from plone.registry.interfaces import IRegistry
-from zope.component import getMultiAdapter
 from zope.component import getUtility
 
 
 configjs = """requirejs.config({
-    baseUrl: '%s',
+    baseUrl: PORTAL_URL,
     paths: %s,
     shim: %s,
     optimize: 'uglify',
@@ -52,12 +51,6 @@ def registryResources(self):
         return self.registry.collectionOfInterface(
             IResourceRegistry, prefix="plone.resources", check=False)
 
-    def base_url(self):
-        portal_state = getMultiAdapter((self.context, self.request),
-                                       name=u'plone_portal_state')
-        site_url = portal_state.portal_url()
-        return site_url
-
     def get_requirejs_config(self):
         """
         Returns the information for requirejs configuration
@@ -85,18 +78,17 @@ def get_requirejs_config(self):
                 # Resources available under name-url name
                 src = script.url
                 paths[name + '-url'] = src
-        return (self.base_url(), paths, shims)
+        return (paths, shims)
 
 
 class ConfigJsView(RequireJsView):
     """ config.js for requirejs for script rendering. """
 
     def __call__(self):
-        (baseUrl, paths, shims) = self.get_requirejs_config()
+        (paths, shims) = self.get_requirejs_config()
         self.request.response.setHeader("Content-Type",
                                         "application/javascript")
         return configjs % (
-            baseUrl,
             json.dumps(paths, indent=4),
             _format_shims(shims)
         )
diff --git a/Products/CMFPlone/resources/browser/scripts.py b/Products/CMFPlone/resources/browser/scripts.py
--- a/Products/CMFPlone/resources/browser/scripts.py
+++ b/Products/CMFPlone/resources/browser/scripts.py
@@ -3,6 +3,7 @@
 
 from Products.CMFPlone.resources.browser.cook import cookWhenChangingSettings
 from Products.CMFPlone.resources.browser.resource import ResourceView
+from zope.component import getMultiAdapter
 
 
 class ScriptsView(ResourceView):
@@ -107,6 +108,12 @@ def default_resources(self):
         })
         return result
 
+    def base_url(self):
+        portal_state = getMultiAdapter((self.context, self.request),
+                                       name=u'plone_portal_state')
+        site_url = portal_state.portal_url()
+        return site_url
+
     def scripts(self):
         """The requirejs scripts, the ones that are not resources are loaded on
         configjs.py


Test patch: