sebduggan / muraURLTools

Mura plugin for managing alternative URLs and redirection
10 stars 11 forks source link

Feature Request: Dev / Production / Local asset src rewriting #25

Open gregmoser opened 11 years ago

gregmoser commented 11 years ago

Typically as part of our workflow we setup a dev or production server and update all of the content and assets. But then our developers code locally and just reference a remote datasource.

When we do that I will typically add a little bit of logic in onRenderEnd() to check if I'm on a local machine. If so it will rewrite all of the output src's with fully qualified paths. I think it would be really cool to add this to the urlTools plugin, and then allow there to be some extended attributes where in the install you could map a current CGI to a rewrite src.

This might also be able to be extended so that you could host all of you assets one server in a cluster, or setup some other type of CDN setup.

The settings for this should probably be an extended attribute of the site, where the existing urlTools values are extended attributes of content.

    <cffunction name="onRenderEnd">
        <cfargument name="$" />

        <!--- Logic to replace the /default/assets/ directory to a fully qualified path when running locally --->
        <cfif not find(".", CGI.HTTP_HOST)>
            <cfset var replacedContent = replace( $.event('__muraresponse__'), '/default/assets/', 'http://#$.siteConfig("domain")#/default/assets/', 'all') />
            <cfset replacedContent = replace( replacedContent, '/default/cache/', 'http://#$.siteConfig("domain")#/default/cache/', 'all') />
            <cfset $.event( '__muraresponse__', replacedContent ) />
        </cfif> 
        <!--- End Asset rewrite --->
    </cffunction>

Interested to hear if anyone would find this useful.

-Greg