refactor(server): moved the server files outside the src to improve static files
This commit is contained in:
52
server/services/general/route/apiHits.ts
Normal file
52
server/services/general/route/apiHits.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["api"],
|
||||
summary: "Tracks the API posts and how often",
|
||||
method: "post",
|
||||
path: "/hits",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: requestSchema},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: responseSchema},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const data = await c.req.json();
|
||||
|
||||
//apiHit(data);
|
||||
|
||||
// Return response with the received data
|
||||
return c.json({
|
||||
message: `Received name: ${data.name}, arrayData: ${data.arrayData}`,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user