Configuration

Configure Phyre using phyre.config.js in your project root.

Custom Error Handler

javascript
// phyre.config.js export const errorHandler = { customHandler: true, customHandlerPath: './errorHandler.js' };

Create your error handler:

javascript
// errorHandler.js export function errorHandler(err, req, res, next) { console.error(err); res.status(err.status || 500).json({ error: { message: err.message, stack: process.env.NODE_ENV === 'development' ? err.stack : undefined } }); }

Custom 404 Page

javascript
// phyre.config.js export const _404 = { custom404: true, custom404Path: './src/client/routes/_404.jsx' };

Create your 404 page:

jsx
// src/client/routes/_404.jsx import { Link } from 'react-router'; export default function NotFound() { return ( <div className="min-h-screen flex items-center justify-center"> <div className="text-center"> <h1 className="text-6xl font-bold mb-4">404</h1> <p className="text-xl text-gray-400 mb-8">Page not found</p> <Link to="/" className="px-6 py-3 bg-purple-600 text-white rounded-lg" > Go Home </Link> </div> </div> ); }

Environment Variables

Create a .env file in your project root:

bash
# .env # Server-side only (secure) DATABASE_URL=postgresql://localhost:5432/mydb API_SECRET=your-secret-key # Client-side (exposed to browser) PUBLIC_API_URL=https://api.example.com PUBLIC_GOOGLE_ANALYTICS_ID=UA-XXXXX-Y

💡 Important: Only variables prefixed with PUBLIC_ are available in client-side code. Server-side variables remain private.

Access in your code:

javascript
// Server-side (API routes) const dbUrl = process.env.DATABASE_URL; const secret = process.env.API_SECRET; // Client-side (components) const apiUrl = process.env.PUBLIC_API_URL; const gaId = process.env.PUBLIC_GOOGLE_ANALYTICS_ID;

Port Configuration

Set custom port in .env:

bash
# .env PORT=3000 WSS_PORT=3001

Full Configuration Example

javascript
// phyre.config.js export const errorHandler = { customHandler: true, customHandlerPath: './errorHandler.js' }; export const _404 = { custom404: true, custom404Path: './src/client/routes/_404.jsx' }; export default { packagesStructure: true, packages: [ { name: 'web', prefix: '/' }, { name: 'admin', prefix: '/admin' } ] };