-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
91 lines (70 loc) · 2.22 KB
/
server.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
const express = require("express");
const bodyParser = require("body-parser");
var cors = require("cors");
const morgan = require('morgan');
const ngrok = require('ngrok');
connections = [];
// create express app npm
const app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
global.io = io;
app.use(cors());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// parse requests of content-type - application/json
app.use(bodyParser.json());
app.use(morgan("dev"));
// Configuring the database
const dbConfig = require("./config/db.config.js");
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.set("useCreateIndex", true);
// Connecting to the database
mongoose
.connect(
dbConfig.url,
{
useNewUrlParser: true
}
)
.then(() => {
console.log("Successfully connected to the database");
})
.catch(err => {
console.log("Could not connect to the database. Exiting now...", err.message);
process.exit();
});
// define a simple route
app.get("/", (req, res) => {
res.json({ message: "Welcome to job portal" });
});
const publicDir = require('path').join(__dirname, './images');
// console.log(publicDir);
app.use(express.static(publicDir));
// import all routes at once
require("./config/routes.config")(app);
//require('.//app/routes/custom_clearance_routes')(app)
// listen for requests
let port = process.env.PORT || 5000;
server.listen(port, '153.92.4.132', () => {
console.log("Server is listening on port " + port);
});
// app.listen(8088, () => {
// ngrok.connect(8088).then(ngrokUrl => {
// console.log('server is running');
// endpoint = ngrokUrl
// console.log(`Verification Service running, open at ${endpoint}`)
// })
// })
// opening Socket Connection.
io.sockets.on('connection', function (socket) {
// console.log(socket.id);
connections.push(socket);
console.log('connected: %s socket connected', connections.length)
// Disconnect the socket
socket.on('disconnect', function (data) {
connections.splice(connections.indexOf(socket), 1)
console.log('Disconnected: %s socket connected', connections.length)
})
})