feat(tcpserver): added in the intial tcpServer startup
This commit is contained in:
48
server/services/tcpServer/route/restartServer.ts
Normal file
48
server/services/tcpServer/route/restartServer.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {startTCPServer, stopTCPServer} from "../tcpServer.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional().openapi({example: "user access"}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["Server:TCP"],
|
||||
summary: "Restarts the tcp server up",
|
||||
method: "get",
|
||||
path: "/",
|
||||
middleware: authMiddleware,
|
||||
description: "Restarts the tcs server with a delay to allow for the entire system to stop and start back up.",
|
||||
responses: {
|
||||
200: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "Succefull restart",
|
||||
},
|
||||
400: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "Failed to restart server",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: "api/tcpServer/restart"});
|
||||
|
||||
try {
|
||||
const tcpStopServer = stopTCPServer();
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
const tcpServer = startTCPServer();
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
return c.json({success: tcpServer.success, message: tcpServer.message}, 200);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
||||
return c.json({success: false, message: "Error in setting the user access", data: error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
46
server/services/tcpServer/route/startServer.ts
Normal file
46
server/services/tcpServer/route/startServer.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {startTCPServer} from "../tcpServer.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional().openapi({example: "user access"}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["Server:TCP"],
|
||||
summary: "Starts the tcp server up",
|
||||
method: "get",
|
||||
path: "/",
|
||||
middleware: authMiddleware,
|
||||
description: "Starts the tcpServer, must be min an admin to start up",
|
||||
responses: {
|
||||
200: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "restarred",
|
||||
},
|
||||
400: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "Failed start",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: "api/tcpServer/start"});
|
||||
|
||||
try {
|
||||
const tcpServer = startTCPServer();
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
return c.json({success: tcpServer.success, message: tcpServer.message}, 200);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
||||
return c.json({success: false, message: "Error in setting the user access", data: error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
46
server/services/tcpServer/route/stopServer.ts
Normal file
46
server/services/tcpServer/route/stopServer.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {stopTCPServer} from "../tcpServer.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional().openapi({example: "user access"}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["Server:TCP"],
|
||||
summary: "Stops the tcp server up",
|
||||
method: "get",
|
||||
path: "/",
|
||||
middleware: authMiddleware,
|
||||
description: "Stops the tcpServer, must be min an admin to start up",
|
||||
responses: {
|
||||
200: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "stopped",
|
||||
},
|
||||
400: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
description: "Failed to stop",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: "api/tcpServer/stop"});
|
||||
|
||||
try {
|
||||
const tcpServer = stopTCPServer();
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
return c.json({success: tcpServer.success, message: tcpServer.message}, 200);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
||||
return c.json({success: false, message: "Error in setting the user access", data: error}, 400);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user