-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (33 loc) · 1.08 KB
/
main.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
require("dotenv").config();
const express = require('express');
const morgan = require("morgan");
const {log} = require("mercedlogger");
const bodyParser = require('body-parser')
const config = require('./config.json');
const port = process.env.PORT || config.port;
const router = require('./routes/api');
const app = express();
const cors = require('cors');
const server = require('http').createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
app.use(cors());
app.use(bodyParser.json());
// app.use(express.static(__dirname + '/public'));
app.use('/api', router);
io.on('connection', (socket) => {
log.magenta('A user connected');
// TODO: Add user to mongo connection list
socket.on('disconnect', () => {
log.magenta('user disconnected');
});
});
// websocket
server.listen(config.port_ws, () => {
log.green("WS STATUS", 'listening on *:' + config.port_ws);
});
// http
app.listen(port, () => {
log.green("SERVER STATUS",'Server started on port ' + port);
});