aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/server/index.ts
blob: ad7f48aeed4f5d030853056273266036045ad2c6 (plain)
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
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { logger } from "hono/logger";
import { createCorsMiddleware, errorHandler } from "./middleware/index.js";
import { auth, cards, decks, study, sync } from "./routes/index.js";

const app = new Hono();

app.use("*", logger());
app.use("/api/*", createCorsMiddleware());
app.onError(errorHandler);

// Chain routes for RPC type inference
const routes = app
	.get("/", (c) => {
		return c.json({ message: "Kioku API" }, 200);
	})
	.get("/api/health", (c) => {
		return c.json({ status: "ok" }, 200);
	})
	.route("/api/auth", auth)
	.route("/api/decks", decks)
	.route("/api/decks/:deckId/cards", cards)
	.route("/api/decks/:deckId/study", study)
	.route("/api/sync", sync);

export type AppType = typeof routes;

const port = Number(process.env.PORT) || 3000;
console.log(`Server is running on port ${port}`);

serve({
	fetch: app.fetch,
	port,
});

export { app };