FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.89k stars 139 forks source link

Programmatic config #743

Closed geekflyer closed 4 years ago

geekflyer commented 4 years ago

Hi,

a lot of foals config seems to be configured by the config files under config/*.json. I personally don't really like large json or yaml configs, but tend to rather have a single config.ts that provides configuration and makes some conditional config decisions depending on the environment via getters.

With that in mind I was wondering if there's a way to configure foalts programmatically or some other way to swap out / avoid the json/yaml based foal config?

This question is mostly for how I can do that with foalts built-in config parameters, such as https://foalts.gitbook.io/docs/topic-guides/cookbook/request-body-size . For user config I can already do my own thing.

Thanks!

kingdun3284 commented 4 years ago

I think it is necessary to be json file, so that it can be replaced in runtime according to the environment. You can always make a config.ts with programmatic config and statically export it.

example config.ts:

let config="something"
if(process.env.NODE_ENV="development")
 config="anotherthing"
export config
LoicPoullain commented 4 years ago

Hi @geekflyer

Thank you for submitting this issue and so contributing to the improvement of the framework.

Starting from version 2, the framework will also support JS config files to allow more flexibility when needed.

I'm closing the issue in favor of #805 to avoid duplicates.