File size: 1,217 Bytes
afe1de9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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' });
  }
}