-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (37 loc) · 1.12 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
const express = require("express");
const path = require("path");
const cookieParser = require('cookie-parser');
const { User } = require("./models");
const passport = require('passport');
require('./passport-init')(passport);
const session = require('express-session');
const flash = require('connect-flash');
const pug = require('pug');
const app = express();
//configure routers
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users')(passport);
// initialize middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(flash());
// set up static path
app.use(express.static(path.join(__dirname, 'public')));
// set up view engine
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
//initialise passport session
app.use(session({
secret: 'cat',
saveUninitialized: true,
resave: true,
}));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', indexRouter);
app.use('/users', usersRouter);
const port = 4000;
app.listen(port, () => {
console.log(`Server started at port ${port}`);
});