forked from 0perationPrivacy/VoIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
94 lines (77 loc) · 2.73 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
91
92
93
94
const config = require('./config.js');
const express = require('express')
const app = express()
var bodyParser = require('body-parser')
const cors = require("cors");
require('dotenv').config()
const path = require('path');
var RateLimit = require('express-rate-limit');
const server = require('http').createServer(app);
global.io = require('socket.io')(server,{ cors: { origin: '*' } });
var mongoose = require('./config/db.config');
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('database connected successfully!');
});
//app.use(cors());
app.use(cors({ origin: ['http://localhost:8080'], }))
var limiter = new RateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
max: 100,
message: "Slow down your requests!",
headers: false
});
// apply rate limiter to all requests
app.use(limiter);
io.on('connection', socket => {
console.log('a user connected');
socket.on('join_channel', (channel) => {
console.log(`${channel} user joined channel`);
socket.join(channel);
});
socket.on('join_profile_channel', (channel) => {
console.log(`${channel} user joined channel`);
socket.join(channel);
});
});
app.use(express.static(__dirname));
/* app.use((req, res, next) => {
if (req.header('x-forwarded-proto') !== 'https')
res.redirect(`https://${req.header('host')}${req.url}`)
else
next()
}) */
/* if( process.env.HTTPS.trim() === 'true'){
app.enable('trust proxy')
app.use((req, res, next) => {
req.secure ? next() : res.redirect('https://' req.headers.host req.url)
})
} */
// parse requests of content-type - application/json
app.use(bodyParser.json({limit: '500mb',parameterLimit: 10000000}));
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true, limit: '500mb',parameterLimit: 10000000 }));
app.use(express.static(path.join(__dirname, './frontend/dist')));
app.use('/uploads', express.static('uploads'));
app.use('/src', express.static('src'));
require("./app/routes/auth.route")(app);
require("./app/routes/setting.route")(app);
require("./app/routes/profile.route")(app);
require("./app/routes/media.route")(app);
require("./app/routes/contact.route")(app);
require("./app/routes/email.route")(app);
require("./app/routes/call.route")(app);
/*/api/auth/login*/
app.get(`/`, function (req, res) {
//res.send('Hello World')
res.sendFile(path.join(__dirname, './frontend/dist/index.html'));
})
app.get('/:id', function (req, res) {
//res.send('Hello World')
res.sendFile(path.join(__dirname, './frontend/dist/index.html'));
})
app.get('/api/users/', function (req, res) {
res.status(200).json({message: 'success'});
})
server.listen(process.env.PORT)