-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (42 loc) · 1.54 KB
/
server.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
require('dotenv').config();
const express = require('express');
const _ = require('lodash');
const expressLayouts = require('express-ejs-layouts');
const methodOverride = require('method-override');
const session = require('express-session');
const sessionRouter = require('./routes/session_router.js');
const homeRouter = require('./routes/home_router.js');
const bookRouter = require('./routes/book_router.js');
const bookshelfRouter = require('./routes/bookshelf_router.js');
const reviewRouter = require('./routes/review_router.js');
const noteRouter = require('./routes/note_router.js');
const vocabularyRouter = require('./routes/vocabulary_router.js');
const setCurrentUser = require('./middlewares/set_current_user.js');
const ensureLoggedIn = require('./middlewares/ensure_logged_in.js');
const customFunctions = require('./middlewares/custom_functions.js');
const app = express();
const port = process.env.PORT || 8080;
app.set('view engine', 'ejs');
app.use(expressLayouts);
app.use(express.static('static'));
app.use(methodOverride('_method'));
app.use(express.urlencoded());
app.use(session({
cookie: { maxAge: 1000 * 60 * 60 * 24 * 3 },
secret: process.env.SESSION_SECRET || "secret",
resave: false,
saveUninitialized: true
}))
app.use(setCurrentUser);
app.use(customFunctions);
app.use(sessionRouter);
app.use(homeRouter);
app.use(ensureLoggedIn);
app.use(bookRouter);
app.use(bookshelfRouter);
app.use(reviewRouter);
app.use(noteRouter);
app.use(vocabularyRouter);
app.listen(port, () => {
console.log(`Working on port ${port}`);
})