home-lab/backend/index.ts

19 lines
483 B
TypeScript
Raw Normal View History

2024-03-15 09:05:49 +07:00
import { Hono } from "hono";
import { cors } from "hono/cors";
2024-03-15 09:31:14 +07:00
import { serveStatic } from "hono/bun";
2024-03-16 07:52:42 +07:00
import { HTTPException } from "hono/http-exception";
import routes from "./routes/_routes";
2024-03-15 09:05:49 +07:00
const app = new Hono()
.use(cors())
2024-03-16 07:52:42 +07:00
.use("*", serveStatic({ root: "./public" }))
.route("/", routes)
.onError((err, c) => {
if (err instanceof HTTPException) {
return err.getResponse();
2024-03-15 09:05:49 +07:00
}
2024-03-16 07:52:42 +07:00
return c.json({ message: err.message }, 500);
});
2024-03-15 09:05:49 +07:00
export default app;