lefengyang
2026-08-20 d01a28cb030b2cb0ff1d42273c877a0f728519a6
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
40
41
42
43
44
45
46
47
48
import {Hono} from 'hono';
import {serve} from '@hono/node-server';
import {ISearchParams} from '../type';
import {getSearchProvider} from '../search-providers';
import {hostname, port} from "../config";
 
const app = new Hono();
 
app.get('/', (c) => {
    return c.text('WakuWaku API:\n/search');
});
 
app.post('/search', async (c: any) => {
    const params = await c.req.json<ISearchParams>();
    const {stationId, keyword} = params;
 
    if (!stationId || !keyword) {
        return c.json({error: 'stationId and keyword are required'}, 400);
    }
 
    try {
        const provider = getSearchProvider(stationId);
        const result = await provider.search(params);
        console.clear();
        console.clear();
        console.log(`Server running on http://${hostname}:${port}`);
        console.log('last request:')
        console.log({
            ...result,
            dataList:result.dataList.length,
            firstRow:result.dataList[0],
            randomRow:result.dataList[Math.floor(Math.random()*result.dataList.length)],
            lastRow:result.dataList[result.dataList.length-1],
        })
        // logJson(results).catch(console.error)
        return c.json(result);
    } catch (error: any) {
        return c.json({error: error.message}, 500);
    }
});
 
serve({
    fetch: app.fetch,
    port,
    hostname
}, () => {
    console.log(`Server running on http://${hostname}:${port}`);
});