minor import changes

This commit is contained in:
Moon Patel
2023-07-02 17:56:28 +05:30
parent 9ec5021dea
commit cfd207e41f
5 changed files with 18 additions and 14 deletions
+2 -3
View File
@@ -3,7 +3,7 @@ const bodyParser = require("body-parser");
const cors = require("cors");
const authRoutes = require("./routes/auth");
const userRoutes = require("./routes/user");
const roomRoutes = require('./routes/room')
const roomRoutes = require("./routes/room");
const mongoose = require("mongoose");
require("dotenv").config();
@@ -17,7 +17,6 @@ const http = require("http");
const server = http.createServer(app);
const { socketIOServerInit } = require("./socket");
app.use(cors({ origin: "*" }));
app.use(bodyParser.json());
app.use((req, res, next) => {
@@ -37,7 +36,7 @@ app.use((req, res, next) => {
// app.use("/", (req, res, next) => res.send('Hello'));
app.use("/api/auth", authRoutes);
app.use("/api/user", userRoutes);
app.use("/api/room", roomRoutes)
app.use("/api/room", roomRoutes);
app.use((error, req, res, next) => {
const status = error.status || 500;
+2
View File
@@ -1,4 +1,6 @@
const nodemailer = require("nodemailer");
require("dotenv").config();
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
+11 -9
View File
@@ -3,24 +3,26 @@ const uuid = require("uuid");
const { createRoom } = require("../socket");
const { sendEmail } = require("../mail");
const { User } = require("../models/user");
const { checkAuth } = require("../util/auth");
// rooms can only be created through HTTP requests and destroyed only by socket.io server
// and vice versan is not true
router.post("/create", async (req, res, next) => {
// and vice versa is not true
router.post("/create", checkAuth, async (req, res, next) => {
console.log(req.body);
// challenger and challenged are username
const { challenger, challenged } = req.body;
const challengedEmail = await User.findOne({ username: challenged }).email;
const challengedEmail = (await User.findOne({ username: challenged })).email;
console.log(challengedEmail);
const roomID = uuid.v4();
createRoom(roomID, req.body.timeLimit);
sendEmail(
challengedEmail,
`Challenge from ${challenger}`,
`To accept the challenge follow the link: http://192.168.136.99:5173/game/challenges/${challenged}/${roomID} \n login through: http://192.168.136.99:5173/login \n roomid:${roomID}`
);
// sendEmail(
// challengedEmail,
// `Challenge from ${challenger}`,
// `To accept the challenge follow the link: http://192.168.136.99:5173/game/challenges/${challenged}/${roomID} \n login through: http://192.168.136.99:5173/login \n roomid:${roomID}`
// );
res.json({ roomID });
});
+2
View File
@@ -3,7 +3,9 @@ const socket = require("socket.io");
let activeRooms = new Map();
function createRoom(roomID, timeLimit) {
console.log(roomID, "created");
activeRooms.set(roomID, { timeLimit, players: [] });
console.log("Currently active rooms", activeRooms.size);
}
// structure of userDetails: {username,color}
-1
View File
@@ -30,7 +30,6 @@ function checkAuthMiddleware(req, res, next) {
return next(new NotAuthError("Not authenticated."));
}
const authFragments = req.headers.authorization.split(" ");
console.log(authFragments);
if (authFragments.length !== 2) {
console.log("NOT AUTH. AUTH HEADER INVALID.");