I recently hit a major snag with a 1,200 line config/routes.cfm
with Lucee 4.5 throwing a nasty "Method code too large"
exception..
After the wave of panic had subsided.. the fix was relatively simple. By the grace of Odin, coldroute’s drawRoutes()
function can be called multiple times and results in the same routes structure as if it were called a single time.
I split my monstrous routes file into smaller includes located in a new config/routes
directory, then simply included them in the main config/routes.cfm
myapp/config/routes/admin.cfm
drawRoutes() .get(to="admin.Foo##index", name="fooIndex", pattern="admin/foo") .post(to="admin.Foo##update", name="fooUpdate", pattern="admin/foo/update/[key]") ... .end();
myapp/config/routes/public.cfm
drawRoutes() .get(to="public.Pages##index", name="pagesIndex", pattern="/pages") .post(to="public.Pages##show", name="pagesShow", pattern="/pages/show/[key]") ... .end();
myapp/config/routes/user.cfm
drawRoutes() .get(to="users.Bar##index", name="barIndex", pattern="/bars") .get(to="users.Bar##new", name="barNew", pattern="/bars/new") ... .end();
And simply include in the main routes like so:
myapp/config/routes.cfm
include "routes/admin.cfm"; include "routes/public.cfm"; include "routes/user.cfm"; // default routes drawRoutes() .wildcard() .root(to="public.site##home") .end();
I hope this saves you that wave of panic..