-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (31 loc) · 1.19 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
const express = require('express');
const app= express();
const mongoose = require("mongoose");
require("dotenv").config();
const bodyParser = require('body-parser')
const hbs = require('express-handlebars');
const clientSessions = require("client-sessions");
const userRoutes = require("./controllers/userController");
const generalRoutes = require("./controllers/generalController");
const adminRoutes = require("./controllers/adminController");
mongoose.createConnection(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true });
var HTTP_PORT = process.env.PORT || 3030;
function onHttpStart(){
console.log("Express http server listening on: " + HTTP_PORT);
}
app.use(clientSessions({
cookieName: "session",
secret: process.env.SESSION_SECRET,
duration: 5*60*1000,
activeDuration: 5*60*1000
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use("/",generalRoutes);
app.use("/",userRoutes);
app.use("/",adminRoutes);
app.use(express.static(__dirname + '/views'));
app.use(express.static(__dirname + '/public'));
app.engine('.hbs', hbs({extname: '.hbs'}));
app.set('view engine', '.hbs');
app.listen(HTTP_PORT, onHttpStart());