-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (40 loc) · 1.57 KB
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes');
const topicRoutes = require('./routes/topicRoutes');
const interviewRoutes = require('./routes/interviewRoutes');
const buildRouter = require('./Admin/adminRoutes');
const app = express();
const cookieParser = require("cookie-parser")
const { requireAuth, checkUser, adminCheck } = require('./middleware/authMiddleware');
const uploadConfig = require('./middleware/uploadConfig');
const AdminBro = require('admin-bro')
const AdminBroMongoose = require('@admin-bro/mongoose')
const AdminBroOptions = require('./Admin/options');
// middleware
AdminBro.registerAdapter(AdminBroMongoose)
app.use(express.static('public'));
app.use(express.json());
app.use(cookieParser());
app.use(uploadConfig);
// view engine
app.set('view engine', 'ejs');
// database connection
const port = process.env.PORT || '8000';
const dbURI = 'mongodb+srv://akkey:[email protected]/node-auth?retryWrites=true&w=majority';
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => {
app.listen(8000, () => console.log(`Server started on Port ${port}`));
}
)
.catch((err) => console.log(err));
// routes
app.get('*', checkUser);
const adminBro = new AdminBro(AdminBroOptions);
const router = buildRouter(adminBro);
app.get('/admin',adminCheck);
app.use(adminBro.options.rootPath, router);
app.get('/', (req, res) => res.render('home'));
app.use(authRoutes);
app.use(interviewRoutes);
app.use(topicRoutes);