forked from Kaushal-jain01/Hostel-Management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (43 loc) · 1.44 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
//const morgan = require('morgan')
const mongoose = require('mongoose')
require('dotenv').config();
const process = require('process');
const path = require('path')
const nocache = require('nocache')
const MONGOURI = process.env.MONGOURI
const PORT = 3000 || process.env.PORT
const connectDB = async () => {
try {
const conn = await mongoose.connect(MONGOURI);
console.log(`MongoDB Connected: ${conn.connection.host}`);
} catch (error) {
console.log(error);
process.exit(1);
}
}
var expressLayouts = require("express-ejs-layouts");
const express = require('express')
const app = express()
app.use(expressLayouts);
app.use(express.static(path.join(__dirname, "public")))
app.use(nocache())
app.use(express.json({limit: "10mb", extended: true}))
//for public routes
const publicRoute = require("./routes/publicRoute")
app.use('/', publicRoute)
//for user routes
const userRoute = require('./routes/userRoute')
app.use('/', userRoute)
//for admin routes
const adminRoute = require('./routes/adminRoute')
app.use('/admin', adminRoute)
//for warden routes
const wardenRoute = require("./routes/wardenRoute")
app.use('/warden', wardenRoute)
app.get('*', function(req, res){
res.send('What where are you, it\'s a 404', 404);
});
connectDB().then(() => {
app.listen(PORT, () => {
console.log(`Server is running at http://127.0.0.1:${PORT}`) })
})