Application Router

Every ColdBox application has a URL router and can be located by convention at config/Router.cfc. This is called the application router and it is based on the router core class: coldbox.system.web.routing.Router. Here is where you will configure router settings and define routes using our routing DSL.

Please see the latest API Docs for investigating all the methods and properties of the Router.

Tip: Unlike previous versions of ColdBox, the new routing services in ColdBox 5 are automatically configured to detect the base URLs and support multi-domain hosting. There is no more need to tell the Router about your base URL.

Application Router - Router.cfc

config/Router.cfc
// Inherits from Router and FrameworkSuperType
component{

    function configure(){
        // Turn on Full URL Rewrites, no index.cfm in the URL
        setFullRewrites( true );
        
        // Routing by Convention
        route( "/:handler/:action?" ).end();
        
    }
    
}

The application router is a simple CFC that virtually inherits from the core ColdBox Router class and is configured via the configure() method. It will be decorated with all the capabilties to work with any request much like any event handler or interceptor. In this router you will be doing 1 of 2 things:

  1. Configuring the Router

  2. Adding Routes via the Routing DSL

Generated Settings

Once the routing service loads your Router it will create two application settings for you:

  • SESBaseURL : The multi-domain URL base URL of your application: http://localhost

  • HTMLBaseURL : The same path as SESBaseURLbut without any index.cfm in it (Just in case you are using index.cfm rewrite). This is a setting used most likely by the HTML <base> tag.

Configuration Methods

You can use the following methods to fine tune the configuration and operation of the routing services:

function configure(){

    setFullRewrites( true );
    setExtensionDetection( true );
    setValidExtensions( "json,cfm,pdf" );

}

The next sections will discus how to register routes for your application.

Last updated