Routes + Modules

Hello Guys,

At the moment my application has the default routes applied, but I think it may be time for me to tinker with them a little.

I have a security module that we’ve built for handling member management, login, registration etc and it’s all working very nicely. The downside is that the current URLs look like so:

/saas:security/login
/saas:security/logout

/saas:security/accounts/register

and so fourth, all a little messy.

I want to overwrite these with much tidier routes such as.

/login
/logout
/register

Can someone give me a little bit of a hand on how best to put these in place? Ideally I think these routes would be defined inside the module somehow, so they create these nice routes in any application that they happen to be dropped into.

Also, on a similar note - if I have references within the application to the old routes, will they continue to work? or will they break when I put these new routes in place?

Thanks for any help guys.

Robert

Robert,

The Module Config can take all the routes, and do what you want it to do. The docs and samples in the forgeBox code shows some good examples of that in use.

Hi Andrew,

Thanks for a point in the right direction. I’ve spent some time this morning reading the docs and looking at the forge-box module source - but I’m hitting up against a couple of challenges.

In my host application routes.cfm file, I map the modules routes to /security like so:

// Add some friendly routes for the SaaS module.
addModuleRoutes(pattern="/security", module=“saas”);

Then within my module config, I create a route for the /login event like this.

routes = [
{pattern="/login", handler=“security”, action=“login”}
];

And this gives me a new route of /security/login - however, I want to trim it down to just /login - is there any way to do this?

Furthermore - when handlers and buildLink() are used within the application, there doesn’t appear to be any form of reverse lookup - so when a user logs out of the application, the handler in the module send them to /saas:security/login - which differs from the public URL of /login that we want to be distributing, is there any way of activating a reverse lookup so the correct URL us used base don the routes defined?

Thanks.

Robert

The only way you can trim it down to just login, would be to map it completely in the routes.cfm to that module. But it means that you would have routes there if you remove the module.

As the module would need the security in front of the login, then the only other way that I can think of doing this would be to use the module onLoad and add the routes and module unload to remove the routes.

But the caveat there is that it would either chain (add the route to an already existing one) or over write the login handler, which I assume might not be a big deal unless you plan on releasing it for others to use.

Hope that might clear it up some more, I am not sure if there is another way. But that should work.