2021-06-07 14:40:51 +03:00
|
|
|
require('dotenv').config();
|
2021-05-19 18:17:24 +03:00
|
|
|
const http = require('http');
|
2021-05-10 18:47:26 +03:00
|
|
|
const { connectDB } = require('./db');
|
2021-05-19 18:17:24 +03:00
|
|
|
const api = require('./api');
|
2021-05-17 19:23:54 +03:00
|
|
|
const jobs = require('./utils/jobs');
|
2021-05-19 18:17:24 +03:00
|
|
|
const Socket = require('./Socket');
|
|
|
|
const Sockets = require('./Sockets');
|
2021-05-22 20:04:34 +03:00
|
|
|
const associateModels = require('./models/associateModels');
|
2021-06-07 14:40:51 +03:00
|
|
|
const initConfig = require('./utils/initConfig');
|
2021-06-22 15:49:00 +03:00
|
|
|
const Logger = require('./utils/Logger');
|
|
|
|
const logger = new Logger();
|
2021-05-10 18:47:26 +03:00
|
|
|
|
2021-05-06 20:03:31 +03:00
|
|
|
const PORT = process.env.PORT || 5005;
|
|
|
|
|
2021-06-22 14:07:32 +03:00
|
|
|
(async () => {
|
|
|
|
await connectDB();
|
|
|
|
await associateModels();
|
|
|
|
await initConfig();
|
2021-05-10 18:47:26 +03:00
|
|
|
|
2021-06-22 14:07:32 +03:00
|
|
|
// Create server for Express API and WebSockets
|
|
|
|
const server = http.createServer();
|
|
|
|
server.on('request', api);
|
2021-05-10 18:47:26 +03:00
|
|
|
|
2021-06-22 14:07:32 +03:00
|
|
|
// Register weatherSocket
|
|
|
|
const weatherSocket = new Socket(server);
|
|
|
|
Sockets.registerSocket('weather', weatherSocket);
|
2021-05-10 18:47:26 +03:00
|
|
|
|
2021-06-22 14:07:32 +03:00
|
|
|
server.listen(PORT, () => {
|
2021-06-22 15:49:00 +03:00
|
|
|
logger.log(`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`);
|
2021-06-22 14:07:32 +03:00
|
|
|
})
|
|
|
|
})();
|