ColdBox is "forgetting" the routes

I have an issue where if I don’t use the ColdBox application for a while, it seems to forget the routing. Here is the redirect code in the handler:

<cfset event.setValue(“fromLogin”, true) />
<cfset setNextEvent(event=redirectPage, persist=“fromLogin”) />

The problem I had was that the page is https: but the setNextEvent drops the https:

I fixed this in Routes.cfm, which looks like this:

// Allow unique URL or combination of URLs, we recommend both enabled setUniqueURLS(false); // Auto reload configuration, true in dev makes sense to reload the routes on every request //setAutoReload(false); // Sets automatic route extension detection and places the extension in the rc.format variable // setExtensionDetection(true); // The valid extensions this interceptor will detect // setValidExtensions('xml,json,jsont,rss,html,htm'); // If enabled, the interceptor will throw a 406 exception that an invalid format was detected or just ignore it // setThrowOnInvalidExtension(true);

// Base URL
if( cgi.HTTPS is “off” ){
protocol = “http”;
protocol = “https”;
if( len(getSetting(‘AppMapping’) ) lte 1){

// Your Application Routes

but as I said, if I leave the application for a while and come back to it, this no longer works and the https gets lost again. I have to do a fwreinit=1 to get it back.

Any ideas? Or any hints about forcing a fwreinit=1 when it’s needed?


It sounds like your application is timing out, and some sort of HTTP-based call like a load balancer ping is reinitting the app. That base URL is cached for the life of the application and is set by whatever request first hits the framework when it comes up. If you want it ot always be HTTPS then hard code it in that code. Or if it needs to be different per tier, then set it as a setting in your ColdBox settings, and get it with getSetting() in your routing file.

There are lots of different settings in different places. Which setting do you mean?

I mean a setting of your own design. You create it. You set it to whatever you want for each environment using the environment overrides, and you use it in your routes config.

I tried doing it in config/ColdBox.cfc

I’ll let you know how it goes!

Something strange is happening. I added this to Coldbox.cfc

// Custom Settings
settings = {
protocol = “https:”

and then I coded Routes.cfm like this:

if( len(getSetting(‘AppMapping’) ) lte 1){

// Your Application Routes

but now something recursive is happening. I guess AppMapping is getting the host added to it, but the only thing I did different was replace a local variable with getSetting

this is the url that is coming back when I do setNextEvent:

You probably already found this but you have your protocol set to https: with the : after it, then you supply :// after the getSetting call, so it’s doubling up on ::s.

Fix: change your settings to settings = { protocol = “https” }

(without the : on the protocol)

Thanks, David! That seems to have been the issue.

If the base URL changes after a while it’s likely because your application scope times out and the next hit to the server re initializes the application. The routes.cfm file is only run once when the app comes up and then it caches the setting. If the first hit to your app is an HTTP hit (think a load balancer probe or something) then it will cache http for all URLs.

If you want all URLs to be built with HTTPS all the time, then simply remove that if statement based on the cgi scope and just hard code it to https.