-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
40 lines (31 loc) · 762 Bytes
/
app.ts
File metadata and controls
40 lines (31 loc) · 762 Bytes
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
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { secureHeaders } from 'hono/secure-headers';
const app = new Hono();
// Security middleware
app.use(secureHeaders());
// CORS middleware
app.use(
cors({
origin: '*',
allowMethods: ['GET'],
})
);
// API routes
import { searchRoute } from './src/search.ts';
app.route('/api', searchRoute);
// 404 handler
app.notFound((c) => {
return c.json({ error: 'Not Found' }, 404);
});
// Error handler
app.onError((err, c) => {
console.error('Server error:', err);
return c.json({ error: 'Internal Server Error' }, 500);
});
const port = process.env.PORT || 3001;
console.log(`🚀 Server running on http://localhost:${port}`);
export default {
port,
fetch: app.fetch,
};