-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (55 loc) · 2.33 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
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
import dotenv from "dotenv";
import multer from "multer";
import morgan from "morgan";
import path from "path";
import { fileURLToPath } from "url";
import helmet from "helmet";
import { register } from "./controllers/auth.js"
import authRoute from "./routes/auth.js"
import userRoute from "./routes/user.js"
import { authenticateJWT } from "./middleware/verifyUser.js"
import { createBlog } from "./controllers/blog.js"
import blogRoute from "./routes/blog.js"
import searchRoute from "./routes/search.js"
import conversationRoute from "./routes/conversations.js";
import messageRoute from "./routes/messages.js";
import { getBlog } from "./controllers/blog.js"
import interestRoute from "./routes/interests.js";
import eventRoute from "./routes/events.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { createEvent } from "./controllers/events.js";
dotenv.config();
const app = express();
app.use(express.json());
app.use(helmet());
app.use(helmet.crossOriginResourcePolicy({ policy: "cross-origin" }));
app.use(morgan("common"));
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
app.use("/assets", express.static(path.join(__dirname, 'public/assets')));
const storage = multer.memoryStorage();
const upload = multer({ storage });
app.use("/auth/register", upload.single("pfp"), register);
app.use("/blog/create", authenticateJWT, upload.single("banner"), createBlog);
app.use("/events/new", upload.single("image"), createEvent);
app.use("/auth", authRoute);
app.use("/blog", authenticateJWT, blogRoute);
app.use("/user", authenticateJWT, userRoute);
app.use("/blog/:id", getBlog);
app.use("/search", authenticateJWT, searchRoute);
app.use("/conversations", conversationRoute);
app.use("/messages", messageRoute);
app.use("/interests", authenticateJWT, interestRoute);
//socketio work
app.use("/events", eventRoute);
//port
const PORT = process.env.PORT || 5000;
mongoose.connect(process.env.CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)))
.catch((error) => console.log(error.message));