@flavoai/fastfold
Version:
Zero-boilerplate backend for React apps with auto-generated CRUD and declarative security
95 lines • 4.12 kB
JavaScript
import Fastfold, { Security } from './index';
import { db } from './db';
import { schema } from './schema';
// ============================================================================
// DEVELOPMENT SERVER WITH DRIZZLE
// ============================================================================
async function startDevServer() {
console.log('🚀 Starting Fastfold development server with Drizzle...');
// Use new Drizzle-based API
const adapter = await Fastfold.quickStart({
// Drizzle integration
drizzle: { db, schema },
// Security + CRUD permissions per table
tables: {
users: {
security: Security.public(),
operations: ['create', 'read', 'update', 'delete']
},
posts: {
security: Security.public(),
operations: ['create', 'read', 'update', 'delete']
}
},
// Custom endpoints
endpoints: (app) => {
// Get posts with their authors
app.get('/api/posts-with-authors', Security.public(), async (req, res) => {
const postsWithAuthors = await adapter.queryWithRelations('posts', {
with: {
author: { columns: { name: true, email: true } }
},
orderBy: { createdAt: 'desc' }
});
res.json({
success: true,
data: postsWithAuthors
});
});
// Create sample data endpoint
app.post('/api/seed', Security.public(), async (req, res) => {
try {
// Create sample users
const user1 = await adapter.create('users', {
name: 'John Doe',
email: 'john@example.com'
});
const user2 = await adapter.create('users', {
name: 'Jane Smith',
email: 'jane@example.com'
});
// Create sample posts
const post1 = await adapter.create('posts', {
title: 'Welcome to Fastfold!',
content: 'This is a simple blog built with Fastfold and Drizzle.',
authorId: user1.id
});
const post2 = await adapter.create('posts', {
title: 'Getting Started with Drizzle',
content: 'Learn how to use Drizzle ORM with Fastfold for rapid development.',
authorId: user2.id
});
res.json({
success: true,
message: 'Sample data created',
data: { users: [user1, user2], posts: [post1, post2] }
});
}
catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
},
hooks: {
onServerStart: async () => {
console.log('🎉 Fastfold server with Drizzle is ready!');
console.log('🎯 Try these custom endpoints:');
console.log(' POST http://localhost:3001/api/seed (Create sample data)');
console.log(' GET http://localhost:3001/api/posts-with-authors (Posts with authors)');
console.log('💡 Example queries:');
console.log(' const users = await adapter.query("users", {});');
console.log(' const posts = await adapter.queryWithRelations("posts", { with: { author: true } });');
}
}
}, 3001);
return adapter;
}
// ES module equivalent of require.main === module
if (import.meta.url === `file://${process.argv[1]}`) {
startDevServer().catch(console.error);
}
export { startDevServer };
//# sourceMappingURL=dev-server.js.map