-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·47 lines (39 loc) · 1.05 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
import express from "express";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import session from "express-session";
import bookRoutes from "./routes/book.js";
import searchRoutes from "./routes/search.js";
import authRoute from "./routes/auth.js"
import navigateRoute from "./routes/navigate.js"
dotenv.config();
const port = process.env.PORT;
const app = express();
app.set('view engine', 'ejs')
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(session({
secret: 'key',
resave: false,
saveUninitialized: true,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days
secure: false,
httpOnly: true,
},
}));
app.use('/books', bookRoutes);
app.use('/', searchRoutes);
app.use('/', authRoute);
app.use('/direct', navigateRoute);
app.get('/', (req, res) => {
if (req.session.userId) {
res.render('home', {userId: req.session.userId});
} else {
res.render('home');
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
})