[feat] Basic Hono+Drizzle Server
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
import "dotenv/config";
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
import { createClient } from "@libsql/client";
|
||||
|
||||
import { Hono } from "@hono/hono";
|
||||
import { commonResponse } from "./utils/response.ts";
|
||||
|
||||
const client = createClient({
|
||||
url: `file:${process.env.DATABASE_PATH!}`,
|
||||
});
|
||||
const db = drizzle(client);
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
|
||||
app.get("/", (c) => {
|
||||
return commonResponse(c, true, 200, { "hint": "Hello! But nothing here." });
|
||||
});
|
||||
app.get("/ping", (c) => {
|
||||
return commonResponse(c, true, 200, {});
|
||||
});
|
||||
|
||||
Deno.serve(app.fetch);
|
||||
|
||||
const handleExit = () => {
|
||||
console.log("Closing database connection...");
|
||||
db.$client.close();
|
||||
console.log("Disconnected.");
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGINT", handleExit);
|
||||
process.on("SIGTERM", handleExit);
|
||||
Reference in New Issue
Block a user