-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
79 lines (69 loc) · 2.51 KB
/
server.js
File metadata and controls
79 lines (69 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const dotenv = require("dotenv");
const morgan = require("morgan");
const cookieParser = require("cookie-parser");
dotenv.config();
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(morgan("dev"));
// Improved CORS setup for Cookies
app.use(
cors({
origin: ["http://localhost:3000","https://v-satwik-reddy.github.io"],
credentials: true, // **Ensures frontend can send & receive cookies**
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"]
})
);
mongoose.connect(process.env.MONGO_URL,{
maxPoolSize: 200
})
.then(() => console.log("✅ MongoDB Connected"))
.catch((err) => {
console.error("❌ MongoDB Connection Failed:", err);
process.exit(1);
});
require("./scheduler");
// ✅ API Routes
app.use("/auth", require("./routes/auth"));
app.use("/home", require("./routes/home"));
app.use("/tasks", require("./routes/tasks"));
app.get("/",(req,res)=>{
res.send("Welcome to Task Manager API. You can find all the routes in the /routes");
});
app.get("/routes",(req,res)=>{
const routesList = [
{ method: "POST", path: "/auth/signUp" },
{ method: "POST", path: "/auth/login" },
{ method: "POST", path: "/auth/logout" },
{ method: "GET", path: "/auth/verify" },
{ method: "GET", path: "/auth/google" },
{ method: "GET", path: "/auth/google/callback" },
{ method: "GET", path: "/home/" },
{ method: "POST", path: "/tasks/createTask" },
{ method: "POST", path: "/tasks/bulkCreateTasks" },
{ method: "GET", path: "/tasks/getTasks" },
{ method: "PUT", path: "/tasks/updateTask/:id" },
{ method: "DELETE", path: "/tasks/deleteTask/:id" },
{ method: "POST", path: "/tasks/task/:id/upload" },
{ method: "GET", path: "/tasks/task/:id" },
{ method: "GET", path: "/" },
{ method: "GET", path: "/routes" }
];
res.send(routesList);
});
// ✅ Catch-all error handler (for better debugging)
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: "Internal Server Error" });
});
const Redis = require("ioredis");
const redis = new Redis(process.env.REDIS_URL + '?family=0');
// ✅ Start the Server
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`🚀 Server running on http://localhost:${PORT}`);
});