From c74f8e2a5f888fadc2a9b1e21b9ed3c936d03414 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Fri, 7 Mar 2025 05:49:13 -0600 Subject: [PATCH] fix(server): changed the url to always be lowercase when it comes over --- server/index.ts | 25 +++++++++++++++++++++---- server/services/tcpServer/tcpServer.ts | 6 +++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/server/index.ts b/server/index.ts index 574eb97..e6df617 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,3 +1,4 @@ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; import {serve} from "@hono/node-server"; import {OpenAPIHono} from "@hono/zod-openapi"; import {serveStatic} from "@hono/node-server/serve-static"; @@ -10,6 +11,7 @@ import scalar from "./services/general/route/scalar.js"; import system from "./services/server/systemServer.js"; import auth from "./services/auth/authService.js"; import tcpServer from "./services/tcpServer/tcpServer.js"; +import ocme from "./services/ocme/ocmeService.js"; const allowedOrigins = ["http://localhost:3000", "http://localhost:4000", "http://localhost:5173"]; const app = new OpenAPIHono(); @@ -28,6 +30,19 @@ app.use( }) ); +// Middleware to normalize route case +app.use("*", async (c, next) => { + const lowercasedUrl = c.req.url.toLowerCase(); + + // If the URL is already lowercase, continue as usual + if (c.req.url === lowercasedUrl) { + return next(); + } + + // Otherwise, re-route internally + return c.redirect(lowercasedUrl, 308); // 308 preserves the HTTP method +}); + app.doc("/api/ref", { openapi: "3.0.0", info: { @@ -51,10 +66,12 @@ const appRoutes = routes.forEach((route) => { // the catch all api route app.all("/api/*", (c) => c.json({error: "API route not found"}, 404)); -app.all("/ocme/*", async (c) => { - //return ocmeService(c); - c.json({error: "Ocme route not found"}, 404); -}); +app.route("/ocme/", ocme); + +// async (c) => { +// //return ocmeService(c); +// c.json({error: "Ocme route not found"}, 404); +// }); // front end static files app.use("/*", serveStatic({root: "./frontend/dist"})); diff --git a/server/services/tcpServer/tcpServer.ts b/server/services/tcpServer/tcpServer.ts index 6bca1c0..4a3137b 100644 --- a/server/services/tcpServer/tcpServer.ts +++ b/server/services/tcpServer/tcpServer.ts @@ -61,9 +61,9 @@ export const stopTCPServer = () => { return {success: true, message: "TCP Server stopped"}; }; -app.route("/tcpServer/start", startTCP); -app.route("/tcpServer/stop", stopTCP); -app.route("/tcpServer/restart", restartTCP); +app.route("/tcpserver/start", startTCP); +app.route("/tcpserver/stop", stopTCP); +app.route("/tcpserver/restart", restartTCP); // start the server after on system start up startTCPServer();