test(returnres): tryed to make a standard return res but will come back to this later
This commit is contained in:
29
server/globalUtils/routeDefs/returnRes.ts
Normal file
29
server/globalUtils/routeDefs/returnRes.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import type { Context } from "hono";
|
||||||
|
|
||||||
|
export type ReturnRes<T> =
|
||||||
|
| { success: true; message: string; data: T }
|
||||||
|
| { success: false; message: string; error: any };
|
||||||
|
|
||||||
|
export const returnRes = <T>(
|
||||||
|
success: boolean,
|
||||||
|
message: string,
|
||||||
|
data: T | null = null
|
||||||
|
): ReturnRes<T> => {
|
||||||
|
/**
|
||||||
|
* just a simple return to reduce the typing and make sure we are always consitant with our returns.
|
||||||
|
*
|
||||||
|
* data can be an error as well.
|
||||||
|
*/
|
||||||
|
return success
|
||||||
|
? { success, message, data: data as T }
|
||||||
|
: { success, message, error: data ?? "An unknown error occurred" };
|
||||||
|
};
|
||||||
|
|
||||||
|
// export const returnApi = (c:Context,success: boolean, message: string, data?: any, code: number)=>{
|
||||||
|
// /**
|
||||||
|
// * just a simple return to reduce the typing and make sure we are always consitant with our returns.
|
||||||
|
// *
|
||||||
|
// * data can be an error as well.
|
||||||
|
// */
|
||||||
|
// return c.json({success, message, data}, code);
|
||||||
|
// }
|
||||||
@@ -6,7 +6,7 @@ import { serveStatic } from "@hono/node-server/serve-static";
|
|||||||
import { logger } from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { createLog } from "./services/logger/logger.js";
|
import { createLog } from "./services/logger/logger.js";
|
||||||
|
import { WebSocketServer } from "ws";
|
||||||
// custom routes
|
// custom routes
|
||||||
import scalar from "./services/general/route/scalar.js";
|
import scalar from "./services/general/route/scalar.js";
|
||||||
import system from "./services/server/systemServer.js";
|
import system from "./services/server/systemServer.js";
|
||||||
@@ -149,6 +149,7 @@ process.on("uncaughtException", async (err) => {
|
|||||||
process.on("beforeExit", async () => {
|
process.on("beforeExit", async () => {
|
||||||
console.log("Process is about to exit...");
|
console.log("Process is about to exit...");
|
||||||
//await closePool();
|
//await closePool();
|
||||||
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
const port =
|
const port =
|
||||||
|
|||||||
Reference in New Issue
Block a user