anycoder-54d82971 / pages /api /pocketbase.js
00Boobs00's picture
Upload pages/api/pocketbase.js with huggingface_hub
d4965d5 verified
// In-memory mock storage for demonstration purposes
let mockDB = [
{ id: '1', name: 'Project Alpha', created: '2023-10-01' },
{ id: '2', name: 'Deployment Test', created: '2023-10-05' },
];
export default async function handler(req, res) {
try {
if (req.method === 'GET') {
return res.status(200).json({ items: mockDB });
}
if (req.method === 'POST') {
const { name } = req.body;
const newItem = {
id: Date.now().toString(),
name: name,
created: new Date().toISOString().split('T')[0]
};
mockDB.push(newItem);
return res.status(200).json({ success: true, item: newItem });
}
if (req.method === 'DELETE') {
const { id } = req.body;
mockDB = mockDB.filter(item => item.id !== id);
return res.status(200).json({ success: true });
}
return res.status(405).json({ message: 'Method not allowed' });
} catch (error) {
console.error('PocketBase Error:', error);
return res.status(500).json({ message: 'Internal Server Error' });
}
}