cutelyst
4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
You can load configuration settings for your application from configuration files in different formats. Currently Cutelyst supports the INI format read by QSettings and the JSON format read by QJsonDocument. To load the configuration file you have to provide them to the cutelyst server executable cutelystd4-qt6 that will load them into your application or set the file paths to Server::ini or Server::json when integrating it in your own executable.
When loading your application with cutelystd4-qt6 server, you can add the parameter --ini <file>
to load a configuration file in INI format or --json <file>
to load a configuration file in JSON format. When integrating the server into your own executable, you can also directly use Server::json or Server::ini property.
You can specify multiple configuration files that will be processed in order from left to right. The content will be merged together. You could even mix INI and JSON files, but note, that JSON files will be loaded after INI files.
As configuration internally is stored in a QVariantMap, all keys in the sections have to be unique. It is not possible to specify multiple keys, as later keys will overwrite the content of previous keys. When using JSON, only a depth of one level is supported and tested, to be common with the limitations of the INI format. JSON configuration files should contain one root object that contains multiple flat objects similar to the sections of INI files.
Loading two INI configuration files where content will be merged and content from later files will overwrite content from previous files.
cutelystd4-qt6 --ini file1.ini --ini file2.ini [other options...]
This will result in a configuration that would look like the following, if loaded from one single file:
You can use the ini
or json
key from the server section to specify additional config files to load. You can use this key one time per configuration file. But note, that config files from this keys will be added to the end of the list of configuration files to load. See this example of four files where two are specified on command line and two inside the files loaded via command line: cutelystd4-qt6 --ini file1.ini --ini file2.ini [other options...]
This will load the files in following order: file1.ini, file2.ini, file4.ini, file3.ini
Some parts of Cutelyst will read their configuration (optionally) from the configuration file(s) from specific sections. Read the documentation of the component to see what configuration is available.
Component | Config section name |
---|---|
Application | Cutelyst |
Server | server |
CSRFProtection | Cutelyst_CSRFProtection_Plugin |
LangSelect | Cutelyst_LangSelect_Plugin |
Memcached | Cutelyst_Memcached_Plugin |
MemcachedSessionStore | Cutelyst_MemcachedSessionStore_Plugin |
Session | Cutelyst_Session_Plugin |
StaticCompressed | Cutelyst_StaticCompressed_Plugin |
If you have only a few own configuration keys, you could simply add them to the Cutelyst
section. If you have more complex configuration options you can add your own configuration file sections. Look at the section and key names already used by Cutelyst to not use that sections/keys.
Configuration keys added to the Cutelyst
section of your configuration file are available via Application::config(). All other sections, including your own, can be returned by Engine::config().