Skip to content

Commit

Permalink
fixed problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavipatel0 committed Sep 9, 2024
1 parent 6483a56 commit f822394
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
34 changes: 4 additions & 30 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Mailgun from "mailgun.js";
import { messagesCollection } from "./utilities/firebaseInit";
import { calculateDistanceInMeters } from "./actions/calculateDistance";
import { scheduleCron } from "./actions/deleter";
import userAndAuthRouter from "./routes";
import mainRouter from "./routes";

const { createServer } = require("http");
const { Server } = require("socket.io");
Expand Down Expand Up @@ -157,44 +157,18 @@ app.get("/", (req, res) => {
res.send("Echologator API");
});

app.use(userAndAuthRouter);

app.use(mainRouter);









// Error handling
app.get("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {GET}");
res.status(404);
});

app.post("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {POST}");
res.status(404);
});

app.put("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {PUT}");
res.status(404);
});

app.delete("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {DELETE}");
res.status(404);
});

app.listen(express_port, () => {
return console.log(
`[EXP] Listening for requests at http://localhost:${express_port}.`
);
});



//Remove the comments if you want to use the deleter !!!!!!
//scheduleCron(); // Begin searching and collecting Garbage (old messages)

Expand Down
27 changes: 27 additions & 0 deletions server/src/routes/error/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Router } from "express";

const errorRouter = Router();


// Error handling
errorRouter.get("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {GET}");
res.status(404);
});

errorRouter.post("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {POST}");
res.status(404);
});

errorRouter.put("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {PUT}");
res.status(404);
});

errorRouter.delete("*", (req, res) => {
res.json("404: Path could not be found! COULD NOT {DELETE}");
res.status(404);
});

export default errorRouter;
10 changes: 6 additions & 4 deletions server/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Router } from "express";
import authRouter from "./auth";
import userRouter from "./user";
import errorRouter from "./error/error";

const userAndAuthRouter = Router();
const mainRouter = Router();

userAndAuthRouter.use(authRouter);
userAndAuthRouter.use(userRouter);
mainRouter.use(authRouter);
mainRouter.use(userRouter);
mainRouter.use(errorRouter);

export default userAndAuthRouter;
export default mainRouter;
4 changes: 2 additions & 2 deletions server/src/routes/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Router } from "express";
import createUserRoute from "./create";
import deleteUserRoute from "./delete";
import getNearbyUserRoute from "./getNearby";
import updateUserRoute from "./update";
import nearbyUserRoute from "./getNearby";

const userRouter = Router();


userRouter.use(createUserRoute);
userRouter.use(deleteUserRoute);
userRouter.use(getNearbyUserRoute);
userRouter.use(nearbyUserRoute);
userRouter.use(updateUserRoute);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Router } from "express";
import { findNearbyUsers, getConnectedUser } from "../../actions/getConnectedUsers";

const getNearbyUserRoute = Router();
const nearbyUserRoute = Router();

getNearbyUserRoute.get("/users", async (req, res) => {
nearbyUserRoute.get("/users", async (req, res) => {
let query = "";
try {
if (req.query.lat && req.query.lon && req.query.radius) {
Expand Down Expand Up @@ -38,4 +38,4 @@ getNearbyUserRoute.get("/users", async (req, res) => {
}
});

export default getNearbyUserRoute;
export default nearbyUserRoute;

0 comments on commit f822394

Please sign in to comment.