fix(server): changed the url to always be lowercase when it comes over
This commit is contained in:
@@ -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"}));
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user