-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (49 loc) · 1.54 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
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 cookieParser = require('cookie-parser');
const session = require('express-session');
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: 'library',
resave: true,
saveUninitialized: true,
}));
app.use(express.static(path.join(__dirname, '/public')));
require('./src/config/passport')(app);
app.use('/css', express.static(path.join(__dirname, '/node_modules/materialize-css/dist/css')));
app.use('/js', express.static(path.join(__dirname, '/node_modules/materialize-css/dist/js')));
app.set('views', './src/views');
app.set('view engine', 'ejs');
const header = {
title: 'My Library',
nav: [
{
title: 'Books',
href: '/books',
},
{
title: 'Authors',
href: '/authors',
},
],
};
const bookRouter = require('./src/routes/bookRoutes')(header);
const homeRouter = require('./src/routes/homeRoutes')(header);
const adminRouter = require('./src/routes/adminRoutes')(header);
const authRouter = require('./src/routes/authRoutes')(header);
app.use('/', homeRouter);
app.use('/books', bookRouter);
app.use('/admin', adminRouter);
app.use('/auth', authRouter);
app.listen(3000, () => {
debug(`Listening on port: ${chalk.green(port)}`);
});