-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
90 lines (73 loc) · 2.1 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const express = require('express');
const session = require('express-session');
const flash = require('express-flash');
const passport = require('passport');
const initializePassport = require("./passportConfig");
const Pusher = require('pusher');
const {pool} = require('./dbConfig');
initializePassport(passport);
const app = express();
app.set("view engine", 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(express.urlencoded({extended: false}));
app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: false
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
const pusher = new Pusher({
appId: process.env.pusher_app_id,
key: process.env.pusher_key,
secret: process.env.pusher_secret,
cluster: process.env.pusher_cluster,
encrypted: true
});
let pgClient;
pool.connect((err, client) => {
if(err) {
console.log(err);
}
pgClient = client;
client.on('notification', function(msg) {
// console.log(msg);
const events = [
{
channel: 'watch_realtime_bai_xe',
name: 'update-qr',
data: JSON.parse(msg.payload)
},
{
channel: 'watch_realtime_xe',
name: 'update_xe',
data: JSON.parse(msg.payload)
}
]
pusher.triggerBatch(events);
});
client.query('LISTEN watch_realtime_bai_xe');
client.query('LISTEN watch_realtime_xe');
});
const user = require('./routes/user');
const map = require('./routes/map');
const infor = require('./routes/infor');
const rent = require('./routes/rent');
const traxe = require('./routes/traxe');
const history = require('./routes/history');
const admin = require('./routes/admin');
const bill = require('./routes/bill');
//user
app.use('/', user);
app.use('/map', map);
app.use('/infor', infor); //Thông tin tài khoản
app.use('/rent', rent);
app.use('/traxe', traxe);
app.use('/bill', bill);
app.use('/history', history);
//admin
app.use('/admin',admin);
app.listen((process.env.PORT || 3000), (req, res) => {
console.log("Run in port 3000");
});