app.get('/api/products', async (req, res) => { try { const { data: products, error } = await supabase .from('products') .select('*'); if (error) { throw error; } res.json({ success: true, products: products || [] }); } catch (error) { console.error('❌ Products error:', error); res.status(500).json({ success: false, error: error.message }); } }); app.post('/api/addproducts', async (req, res) => { try { const { name, price, description, image_url, category } = req.body; // Basic validation if (!name || !price || !description || !image_url || !category) { return res.status(400).json({ success: false, error: 'All fields (name, price, description, image_url, category) are required' }); } // Insert into Supabase const { data, error } = await supabase .from('products') .insert([ { name, price, description, image_url, category, created_at: new Date().toISOString(), updated_at: new Date().toISOString() } ]) .select('*') .single(); if (error) throw error; res.status(201).json({ success: true, message: '✅ Product created successfully', product: data }); } catch (error) { console.error('❌ Product insert error:', error); res.status(500).json({ success: false, error: error.message }); } }); app.get('/api/backgrounds', async (req, res) => { try { const { data, error } = await supabase .from('backgrounds') .select('*') .order('id', { ascending: true }); if (error) throw error; res.json({ success: true, backgrounds: data || [] }); } catch (err) { console.error('❌ Backgrounds fetch error:', err); res.status(500).json({ success: false, error: err.message }); } }); app.get('/api/poses', async (req, res) => { try { const { data, error } = await supabase .from('poses') .select('*') .order('id', { ascending: true }); if (error) throw error; res.json({ success: true, poses: data || [] }); } catch (err) { console.error('❌ Poses fetch error:', err); res.status(500).json({ success: false, error: err.message }); } }); app.get('/api/effects', async (req, res) => { try { const { data, error } = await supabase .from('effects') .select('*') .order('id', { ascending: true }); if (error) throw error; res.json({ success: true, effects: data || [] }); } catch (err) { console.error('❌ Effects fetch error:', err); res.status(500).json({ success: false, error: err.message }); } });