-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (67 loc) · 2.09 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
82
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import cors from "cors";
import dotenv from "dotenv";
import helmet from "helmet";
import morgan from "morgan";
import User from "./models/User.js";
import userRouter from "./routes/auth.js";
import { login,users,register} from "./controllers/auth.js";
/* CONFIGURATIONS */
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(cors());
app.use(function(req,res,next){
res.header("Access-Control-Allow-Origin","*");
res.header("Access-Control-Allow-Headers","Origin,X-Requested-With,Content-Type,Accept");
next();
})
app.use(express.json());
app.use(userRouter);
/* ROUTES */
// const router = express.Router();
// router.use(express.json());
// router.get("/",(req,res)=>{
// res.send("helllo localhusr");
// })
// router.post("/users",register)
/* MONGOOSE SETUP */
const PORT = process.env.PORT || 6001;
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/attendence');
console.log('Database connected on port 27017 !');
}
app.listen(PORT,()=>{
console.log(`Database connected at Port : ${PORT}`);
})
// mongoose
// .connect(process.env.MONGO_URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// })
// .then(() => {
// app.listen(PORT, () => console.log(`Server Port: ${PORT}`));
// // /* ADD DATA ONE TIME */
// // User.insertMany(users);
// // Post.insertMany(posts);
// })
// .catch((error) => console.log(`${error} did not connect`));
// mongoose
// .connect("mongodb://127.0.0.1:27017/attendence", {
// useNewUrlParser: true,
// useUnifiedTopology: true
// })
// .then(() => {
// console.log(`Database connected at Port : ${PORT}`);
// })
// .catch(err => {
// console.log("Could not connect", err);
// });
// console.log(`Database connected at Port : ${PORT}`);