1.0.6 • Published 4 months ago
hamroun-fullstack v1.0.6
Hamroun Fullstack Framework
Full-stack JavaScript framework with integrated SSR and API handling.
Installation
npm install hamroun-fullstack frontend-hamroun
Usage
import Server, { createElement, useState } from 'hamroun-fullstack';
// Initialize server with options
const app = new Server({
staticDir: './public', // Static files directory
apiDir: './src/api', // API routes directory
clientBundles: ['/dist/client.js'] // Client-side bundles
});
// Define a frontend component
function Counter(props) {
const [count, setCount] = useState(props.initial || 0);
return createElement('button', {
onClick: () => setCount(count + 1)
}, count);
}
// API route
app.getApp().post('/api/increment', (req, res) => {
res.json({ count: req.body.count + 1 });
});
// SSR route with hydration
app.getApp().get('/', (req, res) => {
res.ssr(Counter, { initial: 0 });
});
app.listen(3000);
Features
- Unified API and frontend server
- Server-side rendering
- Client-side hydration
- Automatic API route loading
- Static file serving
- TypeScript support