Is there a way to get hostname subdomain (ex. forum from to give as dynamic parameter for database name in config/database.js ? I'm stuck

Hi all! Thank you for be there

I’m trying to set up a mysql connection with Env.Key DB_DEFAULT (name) and a second parameter when there is no key at this environment to set a dynamic database name equal to a subdomain , for example from i should pass as parameter forum, to be the database name adonis has to resolve.

I have tried with dns library at this point but i think i’m confused and i don’t see how to take request.hostname from adonis at configuration step at this point.

Thanks for help

I have change locales from database to file, and i’m now watching my login web page, but i still have no database name parameter as well, so i’m trying to set Environment variable with request.hostname.split[‘0’] at UserController.js before auth.attempt , but there is no success coz the mysql object in database.js still empty.

You can’t directly do it like that, since config is loaded once at start time and it’s not updated anymore at request time

BUT, there are several solutions
One is in here:

There are also some more solutions proposed in this issue, it’s a good place where to take a look :slight_smile:

1 Like