Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import { Hono } from 'hono';import * as webService from '../services/scraper';
const app = new Hono();
// Scrape a URL and extract text contentapp.post('/scrape', async (c) => { try { const { url, selector } = await c.req.json();
if (!url) { return c.json({ error: 'url required' }, 400); }
const result = await webService.scrapeUrl(url, selector); return c.json(result); } catch (error: any) { console.error('[Web] Scrape error:', error.message); const msg = error.message?.includes('private') ? error.message : 'Scrape failed'; return c.json({ error: msg }, 500); }});
// Web search using DuckDuckGo HTMLapp.get('/search', async (c) => { try { const q = c.req.query('q'); const limit = c.req.query('limit') || '5';
if (!q) { return c.json({ error: 'q (query) parameter required' }, 400); }
const parsedLimit = Math.min(Math.max(parseInt(limit) || 5, 1), 20); const result = await webService.searchDuckDuckGo(String(q), parsedLimit); return c.json(result);
} catch (error: any) { console.error('[Web] Search error:', error.message); return c.json({ error: 'Search failed' }, 500); }});
// Agentic browse endpointapp.post('/browse', async (c) => { try { const { url } = await c.req.json();
if (!url) { return c.json({ error: 'url required' }, 400); }
const result = await webService.agentBrowse(url); return c.json(result); } catch (error: any) { console.error('[Web] Browse error:', error.message); const msg = error.message?.includes('private') ? error.message : 'Browse failed'; return c.json({ error: msg }, 500); }});
export default app;