-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
38 lines (30 loc) · 1.3 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
const express = require('express');
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes');
const cookieParser = require('cookie-parser');
const { requireAuth, checkUser } = require('./middleware/authMiddleware')
const app = express();
// middleware
app.use(express.static('public'));
app.use(express.json());
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }))
// view engine
app.set('view engine', 'ejs');
// database connection
// const PORT = process.env.PORT || 3000;
// app.listen(process.env.PORT || 3000);
// app.listen(process.env.PORT || 3000, function(){
// console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
// });
const dbURI = 'mongodb+srv://admin:[email protected]/LMS?retryWrites=true&w=majority';
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
//.then((result) => app.listen(process.env.PORT || 3000))
.then((result) => app.listen(process.env.PORT || 3000, function () {
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
}))
.catch((err) => console.log(err));
// routes
app.get('*', checkUser);
app.get('/', (req, res) => res.render('index', { title: 'Index' }));
app.use(authRoutes);