2021-06-07 14:40:51 +03:00
|
|
|
require('dotenv').config();
|
2021-05-19 18:17:24 +03:00
|
|
|
const http = require('http');
|
2021-10-06 15:17:31 +03:00
|
|
|
|
|
|
|
// Database
|
2021-05-10 18:47:26 +03:00
|
|
|
const { connectDB } = require('./db');
|
2021-10-06 15:17:31 +03:00
|
|
|
const associateModels = require('./models/associateModels');
|
|
|
|
|
|
|
|
// Server
|
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-10-06 15:17:31 +03:00
|
|
|
|
|
|
|
// Utils
|
|
|
|
const initApp = require('./utils/init');
|
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-06-22 14:07:32 +03:00
|
|
|
(async () => {
|
2021-10-06 15:17:31 +03:00
|
|
|
const PORT = process.env.PORT || 5005;
|
|
|
|
|
|
|
|
// Init app
|
2021-11-14 01:28:43 +03:00
|
|
|
await initApp();
|
2021-06-22 14:07:32 +03:00
|
|
|
await connectDB();
|
|
|
|
await associateModels();
|
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-10-06 15:17:31 +03:00
|
|
|
logger.log(
|
|
|
|
`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
})();
|