60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import {serveStatic} from "hono/bun";
|
|
import {logger} from "hono/logger";
|
|
import {authMiddleware} from "lst-auth";
|
|
import {cors} from "hono/cors";
|
|
import {OpenAPIHono} from "@hono/zod-openapi";
|
|
|
|
//routes
|
|
import auth from "./services/auth/authService";
|
|
import scalar from "./route/scalar";
|
|
// services
|
|
import {ocmeService} from "./services/ocme/ocmeServer";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
app.use("*", logger());
|
|
app.use(
|
|
"*",
|
|
cors({
|
|
origin: "http://localhost:5173",
|
|
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
|
|
allowMethods: ["POST", "GET", "OPTIONS"],
|
|
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
|
maxAge: 600,
|
|
credentials: true,
|
|
})
|
|
);
|
|
|
|
app.doc("/api", {
|
|
openapi: "3.0.0",
|
|
info: {
|
|
version: "1.0.0",
|
|
title: "LST API",
|
|
},
|
|
});
|
|
|
|
// as we dont want to change ocme again well use a proxy to this
|
|
app.all("/ocme/*", async (c) => {
|
|
return ocmeService(c);
|
|
});
|
|
|
|
const routes = [scalar, auth] as const;
|
|
|
|
routes.forEach((route) => {
|
|
app.route("/", route);
|
|
});
|
|
|
|
//app.basePath("/api/auth").route("/login", login).route("/session", session).route("/register", register);
|
|
|
|
//auth stuff
|
|
app.get("/api/protected", authMiddleware, (c) => {
|
|
return c.json({success: true, message: "is authenticated"});
|
|
});
|
|
|
|
app.get("*", serveStatic({root: "../frontend/dist"}));
|
|
app.get("*", serveStatic({path: "../frontend/dist/index.html"}));
|
|
|
|
export default app;
|
|
|
|
//export type ApiRoute = typeof apiRoute;
|