-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (38 loc) · 935 Bytes
/
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
import express from "express";
import cors from "cors";
import { connectMongoDb } from "./db/mongodb.js";
import router from "./routes/routes.js";
import { config } from "dotenv";
config();
const app = express();
const PORT = process.env.PORT || 3000;
const url = process.env.MONGODB_URI;
// cors middleware
const allowedOrigins = [
"http://localhost:5173",
"https://social-media-login-signup-project.vercel.app",
];
app.use(
cors({
origin: allowedOrigins,
methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
cors({
origin: allowedOrigins,
})
);
// importing mongodb function
connectMongoDb(url);
// importing routes
app.use("/api", router);
app.get("/", (req, res) => {
res.send("server running");
});
// server setup
app.listen(PORT, () => {
console.log(`server running on http://localhost:${PORT}`);
});