-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (70 loc) · 2.32 KB
/
index.js
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
80
81
const express = require("express");
const app = express();
const connectDB = require("./db/db");
const cookieParser = require("cookie-parser");
const authRoute = require("./routes/auth.route.js");
const userRoute = require("./routes/user.route.js");
const postRoute = require("./routes/post.routes.js");
const commentRoute = require("./routes/comment.routes.js");
const storyRoute = require("./routes/story.routes.js");
const conversationRoute = require("./routes/conversation.routes.js");
const dotenv = require("dotenv");
const { errorHandler } = require("./middlewares/error.js");
const path = require("path");
const { isAuthenticate } = require("./middlewares/verify.js");
//Middlewares-stack of execution
dotenv.config();
app.use(express.json());
app.use(cookieParser());
//Routes handlers for routes
app.use("/uploads", express.static(path.join(__dirname, "uploads")));
app.use("/api/v1/auth", authRoute);
app.use("/api/v1/user", isAuthenticate, userRoute);
app.use("/api/v1/post", isAuthenticate, postRoute);
app.use("/api/v1/comment", isAuthenticate, commentRoute);
app.use("/api/v1/story", isAuthenticate, storyRoute);
app.use("/api/v1/conversation", isAuthenticate, conversationRoute);
app.use(errorHandler);
app.listen(process.env.PORT, () => {
connectDB();
console.log("Listening on port 5000");
});
//==========================================================================================================================================
/*
app.get("/", (req, res) => {
res.send("hello world");
});
const posts = [
{
id: 1,
title: "First Post",
content: "This is the first content",
},
{
id: 2,
title: "Second Post",
content: "This is the second content",
},
];
app.get("/posts", (req, res) => {
res.json(posts);
});
app.get("/posts/:id", (req, res) => {
const id = parseInt(req.params.id);
console.log(req.params);
const post = posts.find((p) => p.id === id);
if (!post) {
return res.status(404).json({ error: "posts not found" });
}
res.send(post);
});
app.post("/posts", (req, res) => {
const title = "New Post";
const content = "This is a new post";
const newPost = { id: posts.length + 1, title, content };
posts.push(newPost);
res.status(201).json(newPost);
// res.status(201).json(posts);
//To test the 'POST' request , We use PostMan or other API testing tools.....
});
*/