Simple, single-user event aggregation platform, for use in personal websites and other related places.
event-streaming single-user events event-aggregation
at develop 48 lines 1.5 kB view raw
1// ------------------------------------------------------------ 2// Imports 3// ------------------------------------------------------------ 4 5import { Hono } from "hono"; 6import { connect } from "mongoose"; 7 8// Middlewares 9import { logger } from "hono/logger"; 10import { endpointEventGenerator } from "$lib/middlewares/endpointEventGenerator"; 11 12// ------------------------------------------------------------ 13// Database healthcheck and program initialization 14// ------------------------------------------------------------ 15 16// Check if MONGO_URI environment variable is set 17if (!process.env.MONGO_URI) 18 throw new Error("Missing MONGO_URI environment variable"); 19 20// Check if USER_TOKEN environment variable is set 21if (!process.env.USER_TOKEN) 22 throw new Error("Missing USER_TOKEN environment variable"); 23 24console.log("Checking database connection..."); 25 26// Check if database connection succeeds 27await connect(process.env.MONGO_URI) 28 .then(() => { 29 console.log("Database connection successful"); 30 }) 31 .catch((error) => { 32 throw new Error(`Failed to connect to database: ${error.message}`); 33 }); 34 35// Define new Hono instance and bind routes directory 36const app = new Hono() 37 .use(logger()) 38 .use(endpointEventGenerator) 39 .route("/", (await import("./routes")).default); 40 41// ------------------------------------------------------------ 42// Exports 43// ------------------------------------------------------------ 44 45export default { 46 fetch: app.fetch, 47 port: process.env.PORT || 4300, 48};