-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (53 loc) · 1.68 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require('dotenv').config();
const express = require('express');
const morgan = require('morgan');
const mongoose = require('mongoose');
const path = require('path');
const methodOverride = require('method-override');
const PORT = 3000;
// authentication
const session = require('express-session');
const passport = require('passport');
// express app
const app = express();
// individual routes
const adminRouter = require('./routes/adminRouter');
const contactRouter = require('./routes/contactRouter');
const aboutRouter = require('./routes/aboutRouter');
const loginRouter = require('./routes/loginRouter');
// wildcard router subject to delete?
const routes = require('./routes/index');
// connection
require('./config/connection');
// register viewengie
app.set('view engine', 'ejs');
// authentication
app.use(session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize());
app.use(passport.session());
// below is provided by the offiical documentaiton but doesn't work
// app.use(session({
// secret: 'keyboard cat',
// resave: false,
// saveUninitialized: false,
// store: new SQLiteStore({ db: 'sessions.db', dir: './var/db' })
// }));
// app.use(passport.authenticate('session'));
// middleware & static files
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(methodOverride('_method'));
app.use(morgan('dev'));
app.use('/', adminRouter);
app.use('/', contactRouter);
app.use('/', aboutRouter);
app.use('/', loginRouter);
app.use(routes);
app.listen(PORT, () => {
console.log(`The server is listening on port ${PORT}`);
});