-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (47 loc) · 1.38 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
const express = require("express");
const dotenv = require("dotenv");
const dbConnect = require("./dbConnect");
const authRouter = require("./routers/authRouter");
const postsRouter = require("./routers/postsRouter");
const userRouter = require("./routers/userRouter");
const morgan = require("morgan");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const cloudinary = require("cloudinary").v2;
const commentRouter = require("./routers/commentRouter");
dotenv.config("./.env");
// Configuration
cloudinary.config({
// secure: true,
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDNARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
const app = express();
//middlewares
app.use(express.json({ limit: "10mb" }));
app.use(morgan("common"));
app.use(cookieParser());
let origin = "http://localhost:3000";
console.log("here env", process.env.NODE_ENV);
if (process.env.NODE_ENV === "production") {
origin = process.env.CLIENT_ORIGIN;
}
app.use(
cors({
credentials: true,
origin,
})
);
app.use("/auth", authRouter);
app.use("/posts", postsRouter);
app.use("/user", userRouter);
app.use("/comment", commentRouter);
app.get("/", (req, res) => {
res.status(200).send("OK from Server");
});
const PORT = process.env.PORT || 4001;
dbConnect();
app.listen(PORT, () => {
console.log(`listening on port: ${PORT}`);
});