refactor(server): moved the server files outside the src to improve static files
This commit is contained in:
20
server/globalUtils/apiHits.js
Normal file
20
server/globalUtils/apiHits.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z, ZodError } from "zod";
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
export const apiHit = async (c, data) => {
|
||||
try {
|
||||
const forwarded = c.req.header("host");
|
||||
const validatedData = requestSchema.parse(data);
|
||||
return { success: true, data: validatedData };
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof ZodError) {
|
||||
return { success: false, errors: error.errors };
|
||||
}
|
||||
return { success: false, errors: [{ message: "An unknown error occurred" }] };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user