const express = require('express'); const axios = require('axios'); const cors = require('cors'); require('dotenv').config(); const app = express(); app.use(cors()); // ── Embedded Frontend ────────────────────────────────────────────── app.get('/', (req, res) => { res.send(` Trendscout — Find Profitable Product Ideas Fast

🔭 Trendscout

Find profitable digital product ideas — live from GitHub, HuggingFace & Reddit

Real-time trend intelligence
⚡ GitHub 🤗 HuggingFace 💬 Reddit

Enter a niche above and hit Scan Trends to find what's hot right now.

`); }); // ── API Proxies ───────────────────────────────────────────────────── app.get('/api/github', async (req, res) => { const topic = req.query.topic || 'wellness'; try { const since = new Date(Date.now() - 30*24*60*60*1000).toISOString().split('T')[0]; const q = `${topic} created:>${since}`; const response = await axios.get('https://api.github.com/search/repositories', { params: { q, sort: 'stars', order: 'desc', per_page: 6 }, headers: { 'User-Agent': 'Trendscout/1.0', ...(process.env.GITHUB_TOKEN ? { Authorization: `token ${process.env.GITHUB_TOKEN}` } : {}) } }); const items = (response.data.items || []).map(r => ({ title: r.full_name, url: r.html_url, meta: `★ ${r.stargazers_count.toLocaleString()} stars · ${r.language || 'multi'} · ${r.description ? r.description.slice(0,60)+'…' : ''}` })); res.json(items); } catch (err) { res.status(500).json([]); } }); app.get('/api/huggingface', async (req, res) => { const topic = req.query.topic || 'wellness'; try { const response = await axios.get('https://huggingface.co/api/models', { params: { search: topic, sort: 'likes', direction: '-1', limit: 6 } }); const items = (response.data || []).map(m => ({ title: m.id, url: `https://huggingface.co/${m.id}`, meta: `♥ ${m.likes ?? 0} likes · ${(m.tags||[]).slice(0,3).join(', ')}` })); res.json(items); } catch (err) { res.status(500).json([]); } }); app.get('/api/reddit', async (req, res) => { const topic = req.query.topic || 'wellness'; try { const response = await axios.get(`https://www.reddit.com/r/Entrepreneur/search.json`, { params: { q: topic, restrict_sr: 1, sort: 'top', t: 'month', limit: 6 }, headers: { 'User-Agent': 'Trendscout/1.0' } }); const items = (response.data.data?.children || []).map(p => ({ title: p.data.title, url: 'https://reddit.com' + p.data.permalink, meta: `▲ ${p.data.ups.toLocaleString()} upvotes · ${p.data.num_comments} comments` })); res.json(items); } catch (err) { res.status(500).json([]); } }); const PORT = process.env.PORT || 7860; app.listen(PORT, () => console.log(`✅ Trendscout running on port ${PORT}`));