Spaces:
Running
Running
import { Hono } from 'hono'; | |
import { config } from '../config'; | |
const similarityMapsApp = new Hono(); | |
// Similarity maps endpoint - matches Next.js /api/similarity-maps | |
similarityMapsApp.get('/', async (c) => { | |
try { | |
const queryId = c.req.query('queryId'); | |
const idx = c.req.query('idx'); | |
const token = c.req.query('token'); | |
const tokenIdx = c.req.query('tokenIdx'); | |
if (!queryId || !idx || !token || !tokenIdx) { | |
return c.json({ error: 'Missing required parameters' }, 400); | |
} | |
// Note: Similarity maps are dynamic, so no caching | |
const simMapUrl = `${config.backendUrl}/get_sim_map?query_id=${encodeURIComponent(queryId)}&idx=${idx}&token=${encodeURIComponent(token)}&token_idx=${tokenIdx}`; | |
const response = await fetch(simMapUrl); | |
if (!response.ok) { | |
throw new Error(`Backend returned ${response.status}`); | |
} | |
// Backend returns HTML, so we need to return it as text | |
const html = await response.text(); | |
return c.html(html); | |
} catch (error) { | |
console.error('Similarity map error:', error); | |
return c.json({ | |
error: 'Failed to generate similarity map', | |
message: error instanceof Error ? error.message : 'Unknown error' | |
}, 500); | |
} | |
}); | |
export { similarityMapsApp }; |