update 00000
This commit is contained in:
parent
6bbf2137b5
commit
9ed91b4a06
2 changed files with 21 additions and 143 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import Elysia, { t } from "elysia";
|
||||
import { Elysia, t } from "elysia";
|
||||
import { generateToken, getUserData, updateUser } from "./auth.controller";
|
||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||
|
||||
|
|
@ -11,27 +11,10 @@ authRoute.get(
|
|||
detail: {
|
||||
tags: ["Auth"],
|
||||
summary: "Get user data",
|
||||
description: "Retrieve user data by user ID",
|
||||
},
|
||||
params: t.Object({
|
||||
userId: t.String({ description: "The user ID" }),
|
||||
userId: t.String(),
|
||||
}),
|
||||
response: {
|
||||
200: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
data: t.Object({
|
||||
// Define user data properties here
|
||||
// For example:
|
||||
id: t.String(),
|
||||
// Add other fields
|
||||
}),
|
||||
}),
|
||||
404: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -41,27 +24,15 @@ authRoute.post(
|
|||
{
|
||||
detail: {
|
||||
tags: ["Auth"],
|
||||
summary: "Update user data",
|
||||
description: "Update user payment status and expiration date",
|
||||
summary: "Update user",
|
||||
},
|
||||
params: t.Object({
|
||||
userId: t.String({ description: "The user ID to update" }),
|
||||
userId: t.String(),
|
||||
}),
|
||||
body: t.Object({
|
||||
paid_status: t.String({ description: "User payment status" }),
|
||||
package_expire_date: t.String({ description: "Package expiration date" }),
|
||||
paid_status: t.String(),
|
||||
package_expire_date: t.String(),
|
||||
}),
|
||||
response: {
|
||||
200: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
// Add other expected response properties
|
||||
}),
|
||||
400: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -71,23 +42,11 @@ authRoute.get(
|
|||
{
|
||||
detail: {
|
||||
tags: ["Auth"],
|
||||
summary: "Generate authentication token",
|
||||
description: "Generate a new auth token for the specified user",
|
||||
summary: "Generate token",
|
||||
},
|
||||
params: t.Object({
|
||||
userId: t.String({ description: "The user ID" }),
|
||||
userId: t.String(),
|
||||
}),
|
||||
response: {
|
||||
200: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
token: t.String(),
|
||||
}),
|
||||
400: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
}),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -98,7 +57,7 @@ authRoute.get(
|
|||
if (authData.status !== 200) {
|
||||
return authData;
|
||||
} else {
|
||||
const userId: string | any = authData.userId;
|
||||
const userId = authData.userId;
|
||||
const response = await getUserData(userId);
|
||||
if (response?.status === 200) {
|
||||
return {
|
||||
|
|
@ -115,20 +74,7 @@ authRoute.get(
|
|||
{
|
||||
detail: {
|
||||
tags: ["Auth"],
|
||||
summary: "Get current user data",
|
||||
description: "Get currently authenticated user data from cookie",
|
||||
},
|
||||
response: {
|
||||
200: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
token: t.String(),
|
||||
// Add other user data properties
|
||||
}),
|
||||
401: t.Object({
|
||||
status: t.Number(),
|
||||
message: t.String(),
|
||||
}),
|
||||
summary: "Get current user",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
|
|
|||
90
src/app.ts
90
src/app.ts
|
|
@ -4,17 +4,15 @@ import cors from "@elysiajs/cors";
|
|||
import { ENV } from "./config/env";
|
||||
import { api } from "./api";
|
||||
|
||||
const allowedOrigins = [
|
||||
"http://localhost:5175",
|
||||
"http://localhost:5173",
|
||||
"https://dashboard.planpostai.com",
|
||||
"https://canvas.planpostai.com",
|
||||
];
|
||||
|
||||
const app = new Elysia()
|
||||
.use(
|
||||
cors({
|
||||
origin: allowedOrigins,
|
||||
origin: [
|
||||
"http://localhost:5175",
|
||||
"http://localhost:5173",
|
||||
"https://dashboard.planpostai.com",
|
||||
"https://canvas.planpostai.com",
|
||||
],
|
||||
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
||||
allowedHeaders: [
|
||||
"Content-Type",
|
||||
|
|
@ -43,10 +41,9 @@ const app = new Elysia()
|
|||
{ name: "Auth", description: "Authentication related endpoints" },
|
||||
{ name: "Download", description: "Download count related endpoints" },
|
||||
],
|
||||
// Add server information to help Swagger understand your API
|
||||
servers: [
|
||||
{
|
||||
url: ENV.SERVER_URL + ":" + ENV.SERVER_PORT,
|
||||
url: ENV.SERVER_URL,
|
||||
description: "Canvas API Server",
|
||||
},
|
||||
],
|
||||
|
|
@ -57,81 +54,16 @@ const app = new Elysia()
|
|||
detail: {
|
||||
tags: ["Default"],
|
||||
summary: "Server root",
|
||||
description: "Returns a message indicating server is running",
|
||||
},
|
||||
response: {
|
||||
200: t.String(),
|
||||
},
|
||||
})
|
||||
.get("/test-swagger", () => "Test route with complete swagger docs", {
|
||||
.get("/test-swagger", () => "Test route with Swagger docs", {
|
||||
detail: {
|
||||
tags: ["Default"],
|
||||
summary: "Test Swagger",
|
||||
description: "Test route with complete Swagger documentation",
|
||||
},
|
||||
response: {
|
||||
200: t.String(),
|
||||
},
|
||||
})
|
||||
.get(
|
||||
"/debug/routes",
|
||||
() => {
|
||||
return {
|
||||
routes: app.routes.map((route) => ({
|
||||
method: route.method,
|
||||
path: route.path,
|
||||
detail: route.detail
|
||||
? {
|
||||
tags: route.detail.tags,
|
||||
summary: route.detail.summary,
|
||||
}
|
||||
: "No detail",
|
||||
})),
|
||||
};
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
tags: ["Default"],
|
||||
summary: "Debug Routes",
|
||||
description: "Shows all registered routes",
|
||||
},
|
||||
response: {
|
||||
200: t.Object({
|
||||
routes: t.Array(
|
||||
t.Object({
|
||||
method: t.String(),
|
||||
path: t.String(),
|
||||
detail: t.Any(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
},
|
||||
}
|
||||
)
|
||||
.use(api)
|
||||
.onError(({ code, error }) => {
|
||||
console.error(`App Error: ${code}`, error);
|
||||
if (code === "NOT_FOUND") return "Not Found :(";
|
||||
return "An error occurred";
|
||||
});
|
||||
.listen(ENV.SERVER_PORT);
|
||||
|
||||
// Log environment configuration
|
||||
console.log("Environment configuration:", {
|
||||
SERVER_URL: ENV.SERVER_URL,
|
||||
SERVER_PORT: ENV.SERVER_PORT,
|
||||
});
|
||||
|
||||
app.listen(ENV.SERVER_PORT, () => {
|
||||
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
|
||||
console.log(
|
||||
`Swagger docs available at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}/docs`
|
||||
);
|
||||
|
||||
console.log("All registered routes:");
|
||||
app.routes.forEach((route) => {
|
||||
// Also log the detail object to see if routes have Swagger metadata
|
||||
console.log(
|
||||
`${route.method} ${route.path} - Detail: ${route.detail ? "Yes" : "No"}`
|
||||
);
|
||||
});
|
||||
});
|
||||
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}`);
|
||||
console.log(`Swagger docs available at ${ENV.SERVER_URL}/docs`);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue