Configuratie
Alle Finch-configuratie staat in een FinchConfigs-instantie die je eenmalig aanmaakt en doorgeeft aan FinchApp. Deze pagina beschrijft elke optie en het bijbehorende omgevingsvariabele-equivalent.
Projectstructuur
Een typisch Finch-project ziet er zo uit:
.
├── lib/
│ ├── app.dart # FinchApp-opzet en main()
│ ├── configs/
│ │ └── setting.dart # App-niveau constanten (optioneel)
│ ├── controllers/
│ ├── models/
│ ├── db/
│ ├── route/
│ │ ├── web_route.dart
│ │ └── socket_route.dart
│ ├── languages/ # JSON-taalbestanden (en.json, fa.json …)
│ └── widgets/ # Jinja-sjabloonbestanden (*.j2.html)
├── public/ # Statische bestanden die direct worden geserveerd
├── migrations/ # MySQL-migratie SQL-bestanden
├── migrations_sqlite/ # SQLite-migratie SQL-bestanden
├── .env
└── pubspec.yaml
FinchConfigs
FinchConfigs is de centrale configuratieklasse. Alle constructorparameters hebben een bijbehorende .env-fallback.
import 'package:finch/finch_app.dart';
import 'package:finch/finch_tools.dart'; // pathTo(), env
FinchConfigs configs = FinchConfigs(
// --- Server ---
port: (env['DOMAIN_PORT'] ?? '8080').toInt(def: 8080),
ip: '0.0.0.0',
domain: env['DOMAIN'] ?? 'localhost',
domainScheme: env['DOMAIN_SCHEME'] ?? 'http',
// --- Paden ---
publicDir: pathTo(env['PUBLIC_DIR'] ?? './public'),
widgetsPath: pathTo(env['WIDGETS_PATH'] ?? './lib/widgets'),
widgetsType: env['WIDGETS_TYPE'] ?? 'j2.html',
languagePath: pathTo(env['LANGUAGE_PATH'] ?? './lib/languages'),
pathCache: pathTo(env['PATH_CACHE'] ?? './cache_routes'),
pathMigrationMySQL: './migrations',
pathMigrationSQLite: './migrations_sqlite',
// --- Taal ---
languageSource: LanguageSource.json, // of LanguageSource.dart
// dartLanguages: languageDart,
// --- Databases ---
dbConfig: FinchDBConfig(
enable: true,
host: env['MONGODB_CONNECTION'] ?? 'localhost',
port: env['MONGODB_PORT'] ?? '27017',
user: env['MONGODB_USER'] ?? 'root',
pass: env['MONGODB_PASSWORD'] ?? 'password',
dbName: env['MONGODB_NAME'] ?? 'my_app',
auth: env['MONGODB_AUTH'] ?? 'admin',
),
mysqlConfig: FinchMysqlConfig(
enable: true,
host: env['MYSQL_HOST'] ?? 'localhost',
port: (env['MYSQL_PORT'] ?? '3306').toInt(def: 3306),
user: env['MYSQL_USER'] ?? 'db_user',
pass: env['MYSQL_PASS'] ?? 'db_password',
databaseName: env['MYSQL_DATABASE'] ?? 'my_db',
),
sqliteConfig: FinchSqliteConfig(
enable: true,
filePath: env['SQLITE_PATH'] ?? './app.sqlite',
),
// --- E-mail ---
mailDefault: '[email protected]',
mailHost: 'smtp.example.com',
// --- Sjabloonengine (Jinja) ---
blockStart: '{%',
blockEnd: '%}',
variableStart: '{{',
variableEnd: '}}',
commentStart: '{#',
commentEnd: '#}',
// --- Beveiliging ---
cookiePassword: env['COOKIE_PASSWORD'] ?? 'change-me-in-production',
// --- Ontwikkeling ---
enableLocalDebugger: (env['ENABLE_LOCAL_DEBUGGER'] ?? false).toString().toBool,
);
Referentie van belangrijkste eigenschappen
| Eigenschap | Type | Standaard | Doel |
|---|---|---|---|
port |
int |
8080 |
HTTP-serverpoort |
ip |
String |
'0.0.0.0' |
Bind-adres |
domain |
String |
'localhost' |
Publiek domein |
domainScheme |
String |
'http' |
http of https |
domainPort |
int |
zelfde als port |
Poort in gegenereerde URL's |
publicDir |
String |
'public' |
Root voor statische bestanden |
widgetsPath |
String |
'bin/widgets' |
Sjablonenmap |
widgetsType |
String |
'html' |
Bestandsextensie van sjabloon |
languagePath |
String |
'languages' |
Map met JSON-taalbestanden |
languageSource |
LanguageSource |
.json |
.json of .dart |
pathCache |
String |
'./cache' |
Cachemap voor route-antwoorden |
pathMigrationMySQL |
String |
'./migrations' |
MySQL-migratiemap |
pathMigrationSQLite |
String |
'./migrations_sqlite' |
SQLite-migratiemap |
cookiePassword |
String |
'password' |
Sleutel voor versleutelde cookies |
enableLocalDebugger |
bool |
false |
Debugbalk inschakelen in de browser |
fakeDelay |
int |
0 |
Kunstmatige responsvertraging (ms) |
poweredBy |
String |
'Dart Finch' |
Waarde van X-Powered-By-header |
noStop |
bool |
true |
Server actief houden na een onverwerkte fout |
Databaseconfiguratieklassen
FinchDBConfig (MongoDB)
FinchDBConfig(
enable: true,
host: 'localhost',
port: '27017', // String
user: 'root',
pass: 'password',
dbName: 'my_app',
auth: 'admin', // Authenticatiebron-database
)
FinchMysqlConfig
FinchMysqlConfig(
enable: true,
host: 'localhost',
port: 3306, // int
user: 'db_user',
pass: 'db_password',
databaseName: 'my_db',
collation: 'utf8mb4_general_ci',
)
FinchSqliteConfig
FinchSqliteConfig(
enable: true,
filePath: './app.sqlite',
)
Omgevingsvariabelen (.env)
Finch leest automatisch een .env-bestand in de projectroot. Alle FinchConfigs-waarden kunnen worden overschreven via omgevingsvariabelen. De env-map (uit finch_tools.dart) biedt toegang tot zowel .env- als systeemomgevingsvariabelen.
DOMAIN_PORT=8080
DOMAIN=example.com
DOMAIN_SCHEME=https
MONGODB_CONNECTION=localhost
MONGODB_PORT=27017
MONGODB_USER=root
MONGODB_PASSWORD=secret
MONGODB_NAME=my_app
MONGODB_AUTH=admin
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=db_user
MYSQL_PASS=db_pass
MYSQL_DATABASE=my_db
SQLITE_PATH=./app.sqlite
ENABLE_LOCAL_DEBUGGER=true
isLocalDebug
FinchApp.config.isLocalDebug geeft true terug wanneer de omgevingsvariabele LOCAL_DEBUG is ingesteld op true, of wanneer Dart wordt uitgevoerd in debugmodus (Console.isDebug). Gebruik deze vlag om uitgebreide uitvoer of de lokale debugbalk in te schakelen.
if (FinchApp.config.isLocalDebug) {
Console.p('Debugmodus actief');
}