Configuration Examples
Complete examples of Lighthouse configuration for different scenarios.
Basic Setup
Minimal configuration for a single service:
// lighthouse.config.ts
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
export default defineLighthouseConfig({
proxy: {
port: 5454,
cors: true,
},
brunoPath: './bruno',
coreGroups: [
{
coreName: 'my-service',
baseUrl: 'http://localhost:4005',
routes: [
{ name: 'api', pathPrefix: '/api/http/' },
],
},
],
processes: [
{
id: 'my-service',
name: 'My Service',
command: 'pnpm',
args: ['dev'],
cwd: './my-service',
mode: 'auto',
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
],
});
Multi-Service Setup
Configuration for multiple services:
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
export default defineLighthouseConfig({
proxy: {
port: 5454,
cors: true,
logRequests: true,
defaultTimeout: 30000,
},
brunoPath: './bruno',
coreGroups: [
{
coreName: 'user-service',
baseUrl: 'http://localhost:4005',
routes: [
{ name: 'users', pathPrefix: '/api/http/user/' },
{ name: 'auth', pathPrefix: '/api/http/auth/' },
],
},
{
coreName: 'order-service',
baseUrl: 'http://localhost:4006',
routes: [
{ name: 'orders', pathPrefix: '/api/http/order/' },
{ name: 'payments', pathPrefix: '/api/http/payment/' },
],
},
{
coreName: 'notification-service',
baseUrl: 'http://localhost:4007',
routes: [
{ name: 'notifications', pathPrefix: '/api/http/notification/' },
],
},
],
processes: [
{
id: 'user-svc',
name: 'User Service',
description: 'Handles user management and authentication',
command: 'pnpm',
args: ['dev'],
cwd: './services/user',
mode: 'auto',
autoStart: true,
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
{
id: 'order-svc',
name: 'Order Service',
description: 'Handles orders and payments',
command: 'pnpm',
args: ['dev'],
cwd: './services/order',
mode: 'auto',
healthCheck: {
url: 'http://localhost:4006/health',
interval: 5000,
},
},
{
id: 'notification-svc',
name: 'Notification Service',
description: 'Handles notifications',
command: 'pnpm',
args: ['dev'],
cwd: './services/notification',
mode: 'auto',
healthCheck: {
url: 'http://localhost:4007/health',
interval: 5000,
},
},
],
ui: {
defaultLayout: 'split',
},
});
Complex Routing
Configuration with advanced routing:
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
export default defineLighthouseConfig({
proxy: {
port: 5454,
cors: true,
},
brunoPath: './bruno',
coreGroups: [
{
coreName: 'api',
baseUrl: 'http://localhost:4005',
routes: [
// Simple routes
{ name: 'users', pathPrefix: '/api/http/user/' },
{ name: 'orders', pathPrefix: '/api/http/order/' },
// Complex routing with routeByPath
{
name: 'global',
routeByPath: {
'v2/users': {
pathPrefix: '/api/http/users/',
preserveMatchedPath: true,
},
'v2/orders': {
pathPrefix: '/api/http/orders/',
preserveMatchedPath: true,
},
'v1': {
pathPrefix: '/api/http/legacy/',
transformPath: (path) => path.replace('/v1/', '/'),
},
'': {
pathPrefix: '/api/http/global/',
},
},
},
],
},
],
processes: [
{
id: 'api',
name: 'API Server',
command: 'pnpm',
args: ['dev'],
cwd: './api',
mode: 'auto',
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
],
});
With External Services
Configuration mixing managed and external services:
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
export default defineLighthouseConfig({
proxy: {
port: 5454,
cors: true,
},
brunoPath: './bruno',
coreGroups: [
{
coreName: 'api',
baseUrl: 'http://localhost:4005',
routes: [{ name: 'api', pathPrefix: '/api/http/' }],
},
],
processes: [
// Managed process
{
id: 'api',
name: 'API Server',
command: 'pnpm',
args: ['dev'],
cwd: './api',
mode: 'managed',
autoStart: true,
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
// External process (Docker)
{
id: 'postgres',
name: 'PostgreSQL',
description: 'Database (Docker)',
command: 'docker',
args: ['compose', 'up', 'postgres'],
cwd: '.',
mode: 'external',
healthCheck: {
url: 'http://localhost:5432',
interval: 10000,
timeout: 5000,
},
},
// External process (Redis)
{
id: 'redis',
name: 'Redis',
description: 'Cache (Docker)',
command: 'docker',
args: ['compose', 'up', 'redis'],
cwd: '.',
mode: 'external',
healthCheck: {
url: 'http://localhost:6379',
interval: 10000,
},
},
],
});
Environment-Specific
Different configurations for development and staging:
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
const isDev = process.env.NODE_ENV !== 'staging';
const devProcesses = [
{
id: 'api',
name: 'API Server',
command: 'pnpm',
args: ['dev'],
cwd: './api',
mode: 'auto' as const,
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
];
export default defineLighthouseConfig({
proxy: {
port: isDev ? 5454 : 5455,
cors: isDev,
logRequests: isDev,
},
brunoPath: './bruno',
coreGroups: [
{
coreName: 'api',
baseUrl: isDev
? 'http://localhost:4005'
: 'http://staging-api.internal:4005',
routes: [
{ name: 'api', pathPrefix: '/api/http/' },
],
},
],
processes: isDev ? devProcesses : [], // No managed processes in staging
});
Monorepo Setup
Configuration for a monorepo with multiple packages:
import { defineLighthouseConfig } from '@serverless-monolith/lighthouse';
import path from 'path';
const rootDir = path.resolve(__dirname);
export default defineLighthouseConfig({
proxy: {
port: 5454,
cors: true,
},
brunoPath: path.join(rootDir, 'bruno'),
coreGroups: [
{
coreName: 'serverless-sst',
baseUrl: 'http://localhost:4005',
routes: [
{ name: 'user', pathPrefix: '/api/http/user/' },
{ name: 'order', pathPrefix: '/api/http/order/' },
],
},
{
coreName: 'serverless-onboarding',
baseUrl: 'http://localhost:4006',
routes: [
{ name: 'company', pathPrefix: '/api/http/company/' },
{ name: 'employee', pathPrefix: '/api/http/employee/' },
],
},
],
processes: [
{
id: 'sst',
name: 'Serverless SST',
command: 'pnpm',
args: ['dev'],
cwd: path.join(rootDir, 'packages/serverless-sst'),
mode: 'auto',
env: {
NODE_ENV: 'development',
},
healthCheck: {
url: 'http://localhost:4005/health',
interval: 5000,
},
},
{
id: 'onboarding',
name: 'Serverless Onboarding',
command: 'pnpm',
args: ['dev'],
cwd: path.join(rootDir, 'packages/serverless-onboarding'),
mode: 'auto',
env: {
NODE_ENV: 'development',
},
healthCheck: {
url: 'http://localhost:4006/health',
interval: 5000,
},
},
],
});