KtorAdmin Configuration Guide
Here’s a brief configuration guide
KtorAdmin Configuration Guide
This guide covers the main configurations available in KtorAdmin, including database setup, storage providers, authentication settings, admin panel customizations, and more.
1. Database Configuration
KtorAdmin supports both JDBC and MongoDB as database sources.
Registering a JDBC Database
Registers a new JDBC database. If the key is null
, the database will be considered the default one.
jdbc(
key = null, // This will be the default database for tables without a specific databaseKey
url = environment.config.property("database.url").getString(),
username = environment.config.property("database.username").getString(),
password = environment.config.property("database.password").getString(),
driver = JDBCDrivers.MYSQL
)
Registering a MongoDB Client
Registers a MongoDB database with a server address.
mongo(
key = null, // This will be the default database for collections without a specific databaseKey
databaseName = environment.config.property("mongo.database").getString(),
address = MongoServerAddress(
environment.config.property("mongo.host").getString(),
environment.config.property("mongo.port").getString().toInt()
),
credential = MongoCredential(
environment.config.property("mongo.username").getString(),
environment.config.property("mongo.authDatabase").getString(),
environment.config.property("mongo.password").getString()
),
)
2. Storage Configuration
KtorAdmin supports custom storage providers, AWS S3, and local storage.
Custom Storage Provider
To use a custom storage provider for file handling, register it using:
registerStorageProvider(MyStorageProvider)
AWS S3 Storage Configuration
KtorAdmin supports AWS S3 storage, requiring the following configurations:
registerS3Client(
accessKey = "your-access-key",
secretKey = "your-secret-key",
region = "us-east-1",
endpoint = "https://s3.amazonaws.com"
)
defaultAwsS3Bucket = "my-default-bucket"
awsS3SignatureDuration = Duration.minutes(30)
Local Storage Configuration
For local storage, both mediaPath
and mediaRoot
need to be set:
mediaPath = "/storage/media"
mediaRoot = "/var/www/media"
🔗 More Details
3. Authentication & Security
KtorAdmin provides authentication settings, including login fields, CSRF protection, session management, and rate limiting.
Defining Login Fields
Specifies the authentication fields required for login.
loginFields = listOf(
LoginField("username"),
LoginField("password")
)
Setting CSRF Token Expiration
Defines the expiration time for CSRF tokens in milliseconds.
csrfTokenExpirationTime = 3_600_000L // 1 hour
Configuring Authentication Session Max Age
Sets the maximum session duration for authenticated users.
authenticationSessionMaxAge = Duration.hours(2)
Setting Authentication Name
Defines a custom authentication scheme name.
authenticateName = "MyAuthScheme"
Setting API Rate Limits
Limits the number of allowed API requests per minute.
rateLimitPerMinutes = 100
Debug Mode Configuration
Enables or disables the debug mode for the admin panel.
debugMode = true // Set to true to enable debug mode for detailed logging
4. Admin Panel & Custom Actions
KtorAdmin allows custom dashboards, admin actions, and event listeners.
Registering a Custom Admin Dashboard
Registers a custom admin dashboard.
adminDashboard = MyCustomDashboard()
Registering a Custom Admin Action
Registers a custom action in the admin panel.
registerCustomAdminAction(MyAdminAction)
Registering an Admin Event Listener
Registers an event listener for admin-related events.
registerEventListener(MyEventListener)
Admin Path Configuration
Defines the base path for accessing the admin panel. You can change it from the default admin
to any custom path you prefer.
adminPath = "custom-admin" // Customize the path to the admin panel
Providing Custom Menus:
The provideMenu
function allows adding custom menu items to specific predefined menus in the admin panel. It takes the table name as input and returns a list of menu items to be added. For example, you can add external links or related sections to the menu.
provideMenu { name ->
if (name == "tasks") listOf(
Menu(title = "Github", link = "https://github.com/Amirroid")
) else emptyList()
}
5. Additional Configurations
Configuring TinyMCE
Defines the TinyMCE editor settings for text editing.
tinyMCEConfig = TinyMCEConfig(...)
Enabling CSV & PDF Data Download
Allows data to be downloaded in different formats.
canDownloadDataAsCsv = true
canDownloadDataAsPdf = true
Registering a Custom Value Mapper
Registers a custom value mapper for handling data transformations.
registerValueMapper(MyValueMapper)
Registering a Custom Preview Handler
Registers a preview handler for specific data types.
registerPreview(MyPreview)
This guide provides a concise overview of KtorAdmin’s key configurations. Make sure to check out other sections of the documentation for more details. 🚀
Last updated