-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabcde.js
More file actions
54 lines (41 loc) · 1.2 KB
/
abcde.js
File metadata and controls
54 lines (41 loc) · 1.2 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
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const port = 3000;
const cors = require("cors");
const cors = require('cors');
// const allowedOrigins = ['https://ecom-mayank.vercel.app'];
// // Add the allowed origins
const categoryRoutes = require("./routes/category");
// const corsOptions = {
// origin: function (origin, callback) {
// if (allowedOrigins.indexOf(origin) !== -1 || !origin) {
// callback(null, true);
// } else {
// callback(new Error('Not allowed by CORS'));
// }
// },
// methods: ['GET', 'POST', 'PUT', 'DELETE'],
// allowedHeaders: ['Content-Type', 'Authorization'],
// };
// app.use(cors(corsOptions));
require("dotenv").config();
// app.use(cors());
app.use(cors({origin:"*"}))
app.use(express.json());
app.get("/",(req,res)=>{
res.send("Server is running")
})
app.use("/category",verifyToken,isAdmin,categoryRoutes);
async function connectDB(){
await mongoose.connect(process.env.MONGODB_URI,{
dbName:"ecom-store-db"
})
console.log("DB CONNECTED")
}
connectDB().catch((err)=>{
console.log(err);
})
app.listen(port,(err)=>{
console.log("Server is running on port",port);
})