First upload
This commit is contained in:
41
server/index.js
Normal file
41
server/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Hono } from 'hono'
|
||||
import { logger } from 'hono/logger'
|
||||
import { cors } from 'hono/cors'
|
||||
import { jwt } from 'hono/jwt'
|
||||
|
||||
// Importación de APIs (Rutas)
|
||||
import auth from './api/auth'
|
||||
import db from './api/db'
|
||||
import mail from './api/mail'
|
||||
import soap from './api/soap'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
// --- Middlewares Globales ---
|
||||
app.use('*', logger())
|
||||
app.use('*', cors())
|
||||
|
||||
// --- Gestión de Errores Global ---
|
||||
app.onError((err, c) => {
|
||||
console.error(`[Global Error]: ${err.message}`)
|
||||
const status = err.name === 'JwtTokenInvalid' ? 401 : 500
|
||||
return c.json({
|
||||
success: false,
|
||||
message: err.message || 'Internal Server Error'
|
||||
}, status)
|
||||
})
|
||||
|
||||
// --- Registro de Rutas ---
|
||||
// Nota: La protección JWT ya la pusimos dentro de api/db.ts y api/soap.ts
|
||||
// para permitir que auth y mail (quizás) sean públicos.
|
||||
app.route('/api/auth', auth)
|
||||
app.route('/api/db', db)
|
||||
app.route('/api/mail', mail)
|
||||
app.route('/api/soap', soap)
|
||||
|
||||
// --- Servidor Bun ---
|
||||
export default {
|
||||
port: 3000,
|
||||
fetch: app.fetch,
|
||||
idleTimeout: 120,
|
||||
}
|
||||
Reference in New Issue
Block a user