-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
42 lines (34 loc) · 1001 Bytes
/
index.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
36
37
38
39
40
41
42
import { Hono, type Context } from "hono";
import { etag } from "hono/etag";
import { logger } from "hono/logger";
import { prettyJSON } from "hono/pretty-json";
import { cors } from "hono/cors";
import prisma from "./src/client/prisma";
import apiRouter from "./src/router/router";
const app = new Hono();
app.use("*", etag(), logger());
app.use("*", prettyJSON());
app.use("*", cors());
app.get("/", (c) => {
return c.json({
message: "Welcome To Hono Api!",
});
});
app.get("/seed", (async (c: Context) => {
await prisma.user.create({
data:{
email: "[email protected]",
name: "Muh Zakir Ramadhan",
password: await Bun.password.hash("zakir", { algorithm: 'bcrypt', cost: 10 })
}
})
return c.json({
message: "Data Seed"
}, 201);
}));
app.mount("/api", apiRouter.fetch);
app.notFound((c) => c.json({ message: "Not Found" }, 404));
export default {
port: Bun.env.PORT || 3000,
fetch: app.fetch,
}