Spaces:
Sleeping
Sleeping
| // API Proxy for PocketBase | |
| export default async function handler(req, res) { | |
| const PB_URL = process.env.POCKETBASE_URL || 'http://localhost:8090'; | |
| const COLLECTION = 'example_collection'; | |
| try { | |
| if (req.method === 'GET') { | |
| // const response = await fetch(`${PB_URL}/api/collections/${COLLECTION}/records`); | |
| // const data = await response.json(); | |
| // Mock Data | |
| return res.status(200).json({ | |
| items: [ | |
| { id: '1', name: 'Project Alpha', created: '2023-10-01' }, | |
| { id: '2', name: 'Deployment Test', created: '2023-10-05' }, | |
| ] | |
| }); | |
| } | |
| if (req.method === 'POST') { | |
| const { name } = req.body; | |
| // const response = await fetch(`${PB_URL}/api/collections/${COLLECTION}/records`, { | |
| // method: 'POST', | |
| // headers: { 'Content-Type': 'application/json' }, | |
| // body: JSON.stringify({ name }), | |
| // }); | |
| return res.status(200).json({ success: true, id: Date.now() }); | |
| } | |
| 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' }); | |
| } | |
| } |