-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
35 lines (29 loc) · 936 Bytes
/
app.ts
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
import { swaggerUI } from "@hono/swagger-ui";
import { Hono } from "hono";
import { jwt } from "hono/jwt";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { secureHeaders } from "hono/secure-headers";
import swagger from "../swagger.json";
import moviesRoute from "./routes/movies";
import usersRoute from "./routes/users";
import loginRoute from "./routes/login";
const app = new Hono();
app.use(cors());
app.use(secureHeaders());
app.get("/", swaggerUI({ url: "/doc" }));
app.get("/doc", (c) => {
return c.json(swagger);
});
app.notFound((c) => {
return c.text("Rota inválida", 404);
});
app.onError((err, c) => {
console.error(`${err}`);
return c.json({ message: err.message }, 500);
});
app.route("/api/users", usersRoute);
app.route("/api/login", loginRoute);
app.use("/api/*", jwt({ secret: Bun.env.JWT_SECRET as string }));
app.route("/api/movies", moviesRoute);
export default app;