Plugin Configuration Guide
This guide explains how to configure TSDIAPI plugins in your application.
🚀 Automatic Configuration
When you install a plugin using the CLI, it automatically:
-
Adds the plugin to your
main.ts:import { createApp } from "@tsdiapi/server";
import createPlugin from "@tsdiapi/plugin-name";
createApp({
plugins: [
createPlugin({
// Plugin configuration
})
]
}); -
Extends your
app.config.tswith TypeBox schema for environment variables:import { Type } from "@sinclair/typebox";
export const ConfigSchema = Type.Object({
// Default variables
PORT: Type.Number(),
HOST: Type.String(),
// Plugin variables
PLUGIN_API_KEY: Type.String(),
PLUGIN_TIMEOUT: Type.Number()
}); -
Updates your
.envfile with required variables:PLUGIN_API_KEY=your-key
PLUGIN_TIMEOUT=60
⚙️ Manual Configuration
If you need to reconfigure a plugin or if the automatic configuration was interrupted, use:
tsdiapi config @tsdiapi/plugin-name
This will:
- Prompt for all required configuration values
- Update your
.envfile - Update your
app.config.tsTypeBox schema if needed
🔧 Configuration Options
Plugins can be configured in three ways:
-
Environment Variables (Recommended)
PLUGIN_API_KEY=your-key
PLUGIN_TIMEOUT=60 -
Direct Configuration in main.ts
createPlugin({
apiKey: "your-key",
timeout: 60
}) -
TypeBox Schema in app.config.ts
import { Type } from "@sinclair/typebox";
export const ConfigSchema = Type.Object({
PLUGIN_API_KEY: Type.String(),
PLUGIN_TIMEOUT: Type.Number()
});
📝 Configuration Priority
Configuration values are loaded in this order:
- Direct configuration in
main.ts - Environment variables from
.env(validated against TypeBox schema inapp.config.ts) - Default values from the plugin
🔍 Verifying Configuration
To verify your plugin configuration:
- Check
main.tsfor plugin registration - Check
.envfor required variables - Check
app.config.tsfor TypeBox schema definitions - Run the application to ensure proper initialization
🚨 Common Issues
Missing Configuration
If a plugin reports missing configuration:
tsdiapi config @tsdiapi/plugin-name
Type Errors
If you get type errors:
- Check
app.config.tsfor correct TypeBox schema definitions - Ensure all required variables are defined in
.env - Run
tsdiapi configto update configuration
Environment Variables
If environment variables aren't loading:
- Check
.envfile exists - Verify variable names match TypeBox schema in
app.config.ts - Restart the application