-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (52 loc) · 1.83 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const session = require('express-session');
const sessionStore = require('connect-mongodb-session')(session);
const flash = require('express-flash')
require('dotenv').config();
const server = require('http').createServer(app) // socket.io require http server type
const io = require('socket.io')(server)
const socketFriends = require("./sockets/Friends.sockets")
socketFriends.FriendsRequest(io)
// // socket.io CONFIG
// io.on("connection", (socket)=>{
// console.log("connected");
// // socketInit(socket)
// })
// import Routes
const ErrorRoutes = require('./Routers/errors.routes')
const HomeRoutes = require('./Routers/home.routes')
const AccountsRoutes = require('./Routers/accounts.routes');
app.use(bodyParser.urlencoded({ extended:true}))
app.use(express.static('static'));
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, 'views'));
const STORE = new sessionStore({
uri:'mongodb://127.0.0.1:27017',
collection:"ChatApp",
})
app.use(session({
secret:"expressAppdjashdbasbdjkahsbdjbasdba=-=asd=a-012",
saveUninitialized : false,
resave:true,
cookie:{
maxAge:100*60*60*24*7,
},
store:STORE
}))
var appendLocalsToUseInViews = function(req, res, next)
{
//append request and session to use directly in views and avoid passing around needless stuff
res.locals.user = req.session.user;
next(null, req, res);
}
app.use(appendLocalsToUseInViews);
app.use(flash({ sessionKeyName: 'flashMessage' }));
app.use('/', HomeRoutes)
app.use('/accounts', AccountsRoutes)
app.use(ErrorRoutes)
server.listen(process.env.port_number, process.env.ip, ()=>{
console.log("listening on 127.0.0.1:"+(process.env.port_number).toString())
})