-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (53 loc) · 1.92 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
// check if it's in production
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express')
const exphbs = require('express-handlebars')
const mongoose = require('mongoose')
const bcrypt = require('bcrypt')
const flash = require('express-flash')
const session = require('express-session')
const passport = require('passport')
const User = require('./modal/user')
const methodOverride = require('method-override')
const initializePassport = require('./passport-config')
initializePassport(
passport,
async email => await User.find({email: email}),
async id => await User.find({id: id})
)
const port = 3000
const app = express()
app.use(express.static(__dirname + '/public'))
app.use(express.json())
app.use(express.urlencoded({ limit: '10mb', extended: false}))
app.use(flash())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(methodOverride('_method'))
const indexRouter = require('./routes/index')
const loginRouter = require('./routes/loginpage/login')
const registerRouter = require('./routes/loginpage/register')
const trouble_loggingRouter = require('./routes/loginpage/trouble_logging')
app.use('/', indexRouter)
app.use('/login', loginRouter)
app.use('/register',registerRouter)
app.use('/trouble_Logging', trouble_loggingRouter)
app.engine('hbs',exphbs.engine({extname: '.hbs'}))
app.set('view engine','hbs')
app.set('views','./views')
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser:true,
useUnifiedTopology: true
})
const db = mongoose.connection
db.on('error', error => console.log(error))
db.once('open', () => console.log('Connected to moongoose'))
const currPort = app.listen(process.env.PORT || port)
console.log("Server now listening on port %d", currPort.address().port)