File size: 1,278 Bytes
5dfbe50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
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 };