canvas-backend/src/app.ts
2025-03-19 10:37:06 +06:00

78 lines
1.7 KiB
TypeScript

import { Elysia } from "elysia";
import swagger from "@elysiajs/swagger";
import { ENV } from "./config/env";
import cors from "@elysiajs/cors";
import { api } from "./api";
const allowedOrigins = [
"http://localhost:5175",
"http://localhost:5173",
"https://dashboard.planpostai.com",
"https://canvas.planpostai.com",
];
const app = new Elysia({
tags: ["Default"],
})
.use(
cors({
origin: allowedOrigins,
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
allowedHeaders: [
"Content-Type",
"Authorization",
"X-Requested-With",
"Accept",
"Origin",
"Access-Control-Allow-Origin",
],
credentials: true,
})
)
.use(
swagger({
path: "/docs",
documentation: {
info: {
title: "Canvas API",
version: "1.0.0",
description: "Canvas API Documentation",
},
tags: [
{
name: "Projects",
description: "All APIs related to Projects",
},
{
name: "Uploads",
description: "All APIs related to Uploads",
},
],
},
})
)
.onError(({ code, error }) => {
if (code === "NOT_FOUND") return "Not Found :(";
console.log("hello from app.ts under error");
console.error(error);
});
const api = app.group("/api", (app) => {
app.get("/", () => "API root is working");
// Include all your other routes inside this group
app.use(authRoute);
app.use(projectRoutes);
app.use(uploadRoutes);
app.use(downloadRoute);
return app;
});
// all routes here
app.use(api);
app.listen(ENV.SERVER_PORT, () => {
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
});