59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { Elysia } from "elysia";
|
|
import swagger from "@elysiajs/swagger";
|
|
import cors from "@elysiajs/cors";
|
|
import { ENV } from "./config/env";
|
|
import { api } from "./api";
|
|
|
|
const app = new Elysia()
|
|
.use(
|
|
cors({
|
|
origin: [
|
|
"http://localhost:5175",
|
|
"http://localhost:5174",
|
|
"https://dashboard.planpostai.com",
|
|
"https://dev.dashboard.planpostai.com",
|
|
"https://canvas.planpostai.com",
|
|
"https://canvasdev.planpostai.com",
|
|
],
|
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
|
allowedHeaders: [
|
|
"Content-Type",
|
|
"Authorization",
|
|
"X-Requested-With",
|
|
"Accept",
|
|
"Origin",
|
|
"Access-Control-Allow-Origin",
|
|
],
|
|
credentials: true,
|
|
})
|
|
)
|
|
.get("/test", () => "Hello World", {})
|
|
.post("/test-post", ({ body }) => {
|
|
console.log("Received POST with body:", body);
|
|
return { success: true, received: body };
|
|
})
|
|
.use(api)
|
|
.use(
|
|
swagger({
|
|
path: "/swagger",
|
|
documentation: {
|
|
openapi: "3.1.0",
|
|
info: {
|
|
title: "Canvas API",
|
|
version: "1.0.0",
|
|
description: "Canvas API Documentation",
|
|
},
|
|
},
|
|
})
|
|
)
|
|
.listen(ENV.SERVER_PORT);
|
|
|
|
// Print all registered routes
|
|
console.log("\n📍 Registered Routes:");
|
|
app.routes.forEach((route) => {
|
|
const methods = Object.keys(route.handlers).join(", ");
|
|
console.log(`${methods.padEnd(20)} ${route.path}`);
|
|
});
|
|
|
|
console.log(`\n🦊 Elysia is running at ${ENV.SERVER_URL}`);
|
|
console.log(`Swagger docs available at ${ENV.SERVER_URL}/swagger`);
|