-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (38 loc) · 1.29 KB
/
app.js
File metadata and controls
46 lines (38 loc) · 1.29 KB
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
const express = require('express');
const chalk = require('chalk');
const debug = require('debug')('app');
const morgan = require('morgan');
const path = require('path');
const bodyParser = require('body-parser');
const passport = require('passport');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const auth = require('./src/models/login');
const app = express();
const port = process.env.PORT || 3000;
app.use(morgan('tiny'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({ secret: 'tutorial' }));
auth.localStrategy();
app.use(passport.initialize());
app.use(passport.session());
auth.initalizePassport();
app.use(express.static(path.join(__dirname, '/public/')));
app.set('views', './src/views');
app.set('view engine', 'ejs');
const nav = [
{ link: '/', title: 'Home' },
{ link: '/about', title: 'About' },
{ link: '/contact', title: 'Contact' },
{ link: '/post/create', title: 'Create' },
{ link: '/login', title: 'Login' }
];
const postRouter = require('./src/routes/postRoutes')(nav);
const homeRouter = require('./src/routes/homeRoutes');
app.use('/post', postRouter);
app.use('/', homeRouter);
app.listen(port, () => {
debug(`listening on port ${chalk.green(port)}`);
});