xtablo-source/api/src/index.ts
2025-10-11 12:32:52 +02:00

71 lines
1.8 KiB
TypeScript

import { serve } from "@hono/node-server";
import { run } from "graphile-worker";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import path from "path";
import { fileURLToPath } from "url";
import { config } from "./config.js";
import { publicRouter } from "./public.js";
import { mainRouter } from "./routers.js";
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
const app = new Hono();
app.use(logger());
app.use("*", async (c, next) => {
const corsMiddleware = cors({
origin: config.CORS_ORIGIN,
allowHeaders: [
"Authorization",
"Content-Type",
"Access-Control-Allow-Origin",
"Access-Control-Allow-Credentials",
"Access-Control-Expose-Headers",
],
allowMethods: ["GET", "POST", "PATCH", "OPTIONS", "DELETE"],
exposeHeaders: ["set-cookie"],
credentials: true,
});
return corsMiddleware(c, next);
});
app.route("/api/v1", mainRouter);
app.route("/api/public", publicRouter);
// const worker = async () => {
// const connectionString = `${
// config.SUPABASE_CONNECTION_STRING
// }?ssl=true&sslrootcert=${path.resolve(__dirname, "..", "supabase_ca.crt")}`;
// const runner = await run({
// connectionString,
// concurrency: 1,
// pollInterval: 1000,
// taskDirectory: path.resolve(__dirname, "tasks"),
// noPreparedStatements: true,
// crontabFile: path.resolve(__dirname, "crontab"),
// });
// await runner.promise;
// };
// worker().catch((err) => {
// console.error(err);
// process.exit(1);
// });
serve(
{
fetch: app.fetch,
port: 8080,
},
(info) => {
console.log(`Server is running on http://localhost:${info.port}`);
}
);
// TODO: Add health check endpoint