Is there a way to bypass module routes on a per-request basis?
I’ve tried doing this in onRequestCapture
if (condition)
controller.getInterceptorService().getInterceptor(‘ses’).removeModuleRoutes( modulename );
But it is not per-request (it affects other requests, where condition is false).
Any ideas?
Can you give an example of what you’re trying to do? What are the criteria that decides when a route should be inaccessible during a given request?
The SES interceptor is a singleton, so modifying its config will affect the entire app. Is there a reason you can’t use a preProcess interceptor to redirect the user elsewhere based on your criteria?
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Can you give an example of what you’re trying to do?
Host websites from the same application as the backoffice. (Not the way I would do it, but it’s what we’ve got.)
It generally works, except the module routes are getting in the way before contentbox can do its stuff, hence wanting to skip/disable them when it’s a website request.
The criteria is basically checking hostname/etc, and sets Request.isWebsite in App.cfc before Coldbox gets invoked.
So I had another idea - if the routes themselves can check against Request.isWebsite and count as a failure if it’s true?
It looks like there’s Route Conditions which allows this - is there a way to bulk set that to a default function?
Then I could have one function for the backend and manually override the contentbox-ui ones to a different function, and that should do it.
Ok, so I did use the route condition to get it work, though to set the default I edited the interceptor (so not recommended for people that want simple core-file updates).
This function is called in onApplicationStart to setup the condition functions:
Application.AreaFuncs =
{ isWebsite : function(){ return Request.isWebsite; }
, isBackoffice : function(){ return NOT Request.isWebsite; }
, isAnywhere : function(){ return true; }
};
(Again, the Request.isWebsite variable is setup in onRequestStart, based on hostnames/etc.)
Then the isBackoffice function is set to default by inserting these two lines to the the top of addRoute in /coldbox/system/interceptors/SES.cfc
if ( NOT StructKeyExists(Arguments,‘condition’) )
Arguments.condition = Application.AreaFuncs.isBackoffice;
That saves editing routes in 3-4 dozen module configs that the Backoffice uses, then for just the ones in contentbox-ui/ModuleConfig.cfc, all routes have this:
{pattern="/:pageSlug", handler=“page”, action=“index” , condition=Application.AreaFuncs.isWebsite }
And if we ever have shared modules, we can use the isAnywhere one to reset to default behaviour.