Configuration
Configure your Frame-Master application through the frame-master.config.ts file. Learn about HTTP server settings, plugin configuration, and advanced options.
Overview
Frame-Master uses a single configuration file to define your application's behavior. This file exports a FrameMasterConfig object that controls the HTTP server and plugins.
import type { FrameMasterConfig } from "frame-master/server/types";const config: FrameMasterConfig = {HTTPServer: {port: 3000,hostname: "localhost",},plugins: [],pluginsOptions: {disableHttpServerOptionsConflictWarning: false,},};export default config;
TypeScript Support
FrameMasterConfig type to get autocomplete and type checking in your configuration file.HTTPServer Configuration
The HTTPServer property configures the underlying Bun HTTP server. Frame-Master uses Bun.serve() under the hood, so most Bun.serve options are available.
Basic Server Options
const config: FrameMasterConfig = {HTTPServer: {// Server addressport: 3000,hostname: "localhost",// Development mode (enables Chrome DevTools)development: true,// Server identityid: "my-server-id",// Maximum request body size (in bytes)maxRequestBodySize: 1024 * 1024 * 10, // 10MB},plugins: [],};
portnumber | stringThe port number the server listens on. Can be a number or string.
Default: 3000
hostnamestringThe hostname to bind to. Use '0.0.0.0' to listen on all interfaces, or 'localhost' for local only.
Default: "0.0.0.0"
developmentbooleanEnables development mode with Chrome DevTools integration and better error messages.
Default: false
idstringOptional identifier for the server instance.
maxRequestBodySizenumberMaximum size of request body in bytes. Default is 128MB.
Default: 1024 * 1024 * 128
TLS/SSL Configuration
Enable HTTPS by providing TLS configuration:
import { readFileSync } from "fs";const config: FrameMasterConfig = {HTTPServer: {port: 443,hostname: "example.com",// TLS/SSL configurationtls: {key: readFileSync("./certs/private-key.pem"),cert: readFileSync("./certs/certificate.pem"),// Optional: CA certificateca: readFileSync("./certs/ca-cert.pem"),// Optional: passphrase for encrypted keypassphrase: "my-secret-passphrase",},},plugins: [],};
Certificate Management
- Never commit private keys to version control
- Use environment variables for sensitive paths
- Consider using Let's Encrypt for production certificates
- Test SSL configuration locally before deploying
WebSocket Configuration
Configure WebSocket behavior for real-time communication:
const config: FrameMasterConfig = {HTTPServer: {port: 3000,// WebSocket configurationwebsocket: {// Maximum message size (in bytes)maxPayloadLength: 16 * 1024 * 1024, // 16MB// Idle timeout (in seconds)idleTimeout: 120,// Backpressure limitbackpressureLimit: 1024 * 1024, // 1MB// Enable per-message deflate compressionperMessageDeflate: true,},},plugins: [],};
Plugin WebSockets
Error Handling
Customize error responses and handling:
const config: FrameMasterConfig = {HTTPServer: {port: 3000,// Custom error handlererror(error: Error) {console.error("Server error:", error);return new Response("Internal Server Error", {status: 500,headers: { "Content-Type": "text/plain" },});},},plugins: [],};
Low-Level Options
Advanced server configuration for specific use cases:
const config: FrameMasterConfig = {HTTPServer: {port: 3000,// Unix socket path (alternative to port)unix: "/tmp/my-app.sock",// Reuse port (SO_REUSEPORT)reusePort: true,// Low priority requests handlinglowMemoryMode: false,},plugins: [],};
unixstringUnix domain socket path. If specified, the server will listen on this socket instead of a TCP port.
reusePortbooleanEnable SO_REUSEPORT for multiple processes to bind to the same port.
Default: false
lowMemoryModebooleanOptimize for lower memory usage at the cost of some performance.
Default: false
Plugins Configuration
Plugins extend Frame-Master's functionality. Configure plugins by adding them to the plugins array.
import type { FrameMasterConfig } from "frame-master/server/types";import ReactSSRPlugin from "frame-master-plugin-react-ssr/plugin";import TailwindPlugin from "frame-master-plugin-tailwind";import SessionPlugin from "frame-master-plugin-session/plugin";const config: FrameMasterConfig = {HTTPServer: {port: 3000,},plugins: [// React SSR plugin with optionsReactSSRPlugin({pathToShellFile: ".frame-master/shell.tsx",pathToClientWrapper: ".frame-master/client-wrapper.tsx",pathToBuildDir: ".frame-master/build",}),// Tailwind CSS pluginTailwindPlugin({inputFile: "static/index.css",outputFile: "static/tailwind.css",}),// Session management pluginSessionPlugin({framework: "react",strategy: "cookie",}),],};export default config;
Plugin Order Matters
Plugin Configuration Patterns
Plugin Import
Import plugins from their package's /plugin export path
Plugin Options
Each plugin accepts a configuration object specific to its functionality
Plugin Composition
Combine multiple plugins to build your perfect framework
Plugin Options
Configure global plugin behavior with pluginsOptions.
const config: FrameMasterConfig = {HTTPServer: {port: 3000,},plugins: [// Your plugins here],pluginsOptions: {// Disable warnings when plugins have conflicting server optionsdisableHttpServerOptionsConflictWarning: false,},};
disableHttpServerOptionsConflictWarningbooleanWhen multiple plugins try to set the same HTTPServer option with different values, Frame-Master throws an error by default. Set this to true to suppress the error and allow the last plugin's value to win.
Default: false
Configuration Conflicts
serverConfig hook. If multiple plugins set conflicting values (like different ports), Frame-Master will throw an error unless you disable the warning. Be careful when disabling this as it may lead to unexpected behavior.Configuration Merge Strategy
// Frame-Master merges configurations in this order:// 1. Plugin 1 serverConfig// 2. Plugin 2 serverConfig// 3. Your HTTPServer config (highest priority)// Example:// Plugin A sets: { port: 3000 }// Plugin B sets: { hostname: "0.0.0.0" }// Your config: { port: 8080 }// Result: { port: 8080, hostname: "0.0.0.0" }// Conflict example (throws error by default):// Plugin A sets: { port: 3000 }// Plugin B sets: { port: 4000 }// Error: Conflict in serverConfig plugins
Environment-Specific Configuration
Use environment variables and conditional logic to create environment-specific configurations.
import type { FrameMasterConfig } from "frame-master/server/types";const isDevelopment = process.env.NODE_ENV === "development";const isProduction = process.env.NODE_ENV === "production";const config: FrameMasterConfig = {HTTPServer: {port: parseInt(process.env.PORT || "3000"),hostname: process.env.HOST || "localhost",// Enable development featuresdevelopment: isDevelopment,// Production-only TLS...(isProduction && {tls: {key: Bun.file(process.env.TLS_KEY_PATH!),cert: Bun.file(process.env.TLS_CERT_PATH!),},}),},plugins: [// Conditionally include plugins...(isDevelopment ? [DevToolsPlugin()] : []),],};export default config;
Environment Best Practices
- Create separate
.env.developmentand.env.productionfiles - Use sensible defaults with fallback values (||)
- Validate required environment variables on startup
- Document all environment variables in .env.example
Configuration Validation
import type { FrameMasterConfig } from "frame-master/server/types";// Validate required environment variablesconst requiredEnvVars = ["DATABASE_URL", "API_KEY"];for (const envVar of requiredEnvVars) {if (!process.env[envVar]) {throw new Error(`Missing required environment variable: ${envVar}`);}}// Validate configuration valuesconst port = parseInt(process.env.PORT || "3000");if (isNaN(port) || port < 1 || port > 65535) {throw new Error(`Invalid port number: ${process.env.PORT}`);}const config: FrameMasterConfig = {HTTPServer: { port },plugins: [],};export default config;
Complete Example
A comprehensive configuration example showing all major features.
import type { FrameMasterConfig } from "frame-master/server/types";import ReactSSRPlugin from "frame-master-plugin-react-ssr/plugin";import TailwindPlugin from "frame-master-plugin-tailwind";import SessionPlugin from "frame-master-plugin-session/plugin";import { readFileSync } from "fs";const isDevelopment = process.env.NODE_ENV === "development";const isProduction = process.env.NODE_ENV === "production";const config: FrameMasterConfig = {HTTPServer: {// Basic server configport: parseInt(process.env.PORT || "3000"),hostname: process.env.HOST || "localhost",// Development featuresdevelopment: isDevelopment,// Request limitsmaxRequestBodySize: 1024 * 1024 * 50, // 50MB// TLS/SSL for production...(isProduction && {tls: {key: readFileSync(process.env.TLS_KEY_PATH!),cert: readFileSync(process.env.TLS_CERT_PATH!),},}),// WebSocket configurationwebsocket: {maxPayloadLength: 16 * 1024 * 1024,idleTimeout: 120,perMessageDeflate: true,},// Custom error handlererror(error: Error) {console.error("[Server Error]", error);if (isDevelopment) {return new Response(JSON.stringify({error: error.message,stack: error.stack,}),{status: 500,headers: { "Content-Type": "application/json" },});}return new Response("Internal Server Error", {status: 500,headers: { "Content-Type": "text/plain" },});},},plugins: [// React SSR for UIReactSSRPlugin({pathToShellFile: ".frame-master/shell.tsx",pathToClientWrapper: ".frame-master/client-wrapper.tsx",pathToBuildDir: ".frame-master/build",pathToPagesDir: "src/pages",}),// Tailwind for stylingTailwindPlugin({inputFile: "static/index.css",outputFile: "static/tailwind.css",}),// Session managementSessionPlugin({framework: "react",strategy: "cookie",}),],pluginsOptions: {disableHttpServerOptionsConflictWarning: false,},};export default config;
Best Practices
Use Environment Variables
Store sensitive data and environment-specific values in .env files, not in the config file.
Type Safety
Always use the FrameMasterConfig type to get IDE autocomplete and catch errors early.
Validate Configuration
Add validation logic to catch configuration errors before the server starts.
Document Custom Config
If you add complex logic or custom plugins, document the configuration in your README.
Keep It Simple
Start with minimal configuration and add options only when needed. Frame-Master has sensible defaults.
Next Steps
Explore related topics to deepen your understanding of Frame-Master configuration.
HTTP Server
Learn more about the HTTP server and request handling
Plugin System
Understand how plugins extend Frame-Master's functionality
Official Plugins
Explore official plugins and their configuration options
Deployment
Learn how to deploy your configured application to production
