fix(server): changed the url to always be lowercase when it comes over

This commit is contained in:
2025-03-07 05:49:13 -06:00
parent 402ce734b3
commit c74f8e2a5f
2 changed files with 24 additions and 7 deletions

View File

@@ -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"}));