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