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: {// see Bun documentation for available options},plugins: [],};
Bun.serveobjectrequiredAll options available in Bun.serve() can be used here to configure the HTTP server.
→bun.serve API DocsPlugins 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
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.
