Routes and multiple configs


#1

What is the best practice for using multiple configs and routes? I have some routes that I use for local development to help me out (CSV import etc) but I wont want those on the live server. I have a lot of other routes.

I know that redeclaring the config values in the other configs cancels out previous settings, but how can do some routes in one file and others in other configs without having to redeclare everything?

Hopefully i made sense!


#2

I would put the routes in a seperate file like so

config/
  config.php
  config.localhost.php
  routes.php
  routes-local.php

Then simply require your routes in the appropriate configs.

// config.php

require __DIR__ . DS . 'routes.php';
// config.localhost.php

require __DIR__ . DS . 'routes-local.php';

The routes files should look something like this:

<?php

$kirby = kirby();

$kirby->set('route', [
  'pattern' => 'something',
  'action'  => function () {
    //
  }
]);

#3

Thanks @lukaskleinschmidt That is useful. At least I only have two files to worry about instead of 5. Basically i have routes that i want to use on local and possibly staging. I was hoping to do an array of domains or something and wrap the applicable routes in an if statement. I wont need the extra files then.

80% of the routes apply to all domains, its just two or three that are for dev work.


#4

I mean you can get the domain within the config and react on that. Personally I would stick with the configs as is or perhaps crate a plugin for that use case.


#5

Fair enough. Thanks for your help. I wouldn’t normally bother but one of the routes generates stuff that might be useful to someone up to no good, so id rather it didn’t work on live thats all.