2021-06-07 11:40:51 +00:00
|
|
|
require('dotenv').config();
|
2021-05-19 15:17:24 +00:00
|
|
|
const http = require('http');
|
2021-05-10 15:47:26 +00:00
|
|
|
const { connectDB } = require('./db');
|
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-05-22 17:04:34 +00:00
|
|
|
const associateModels = require('./models/associateModels');
|
2021-06-07 11:40:51 +00:00
|
|
|
const initConfig = require('./utils/initConfig');
|
2021-05-10 15:47:26 +00:00
|
|
|
|
2021-05-06 17:03:31 +00:00
|
|
|
const PORT = process.env.PORT || 5005;
|
|
|
|
|
2021-06-07 11:40:51 +00:00
|
|
|
connectDB()
|
|
|
|
.then(() => {
|
|
|
|
associateModels();
|
|
|
|
initConfig();
|
|
|
|
});
|
2021-05-10 15:47:26 +00:00
|
|
|
|
2021-05-19 15:17:24 +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-05-19 15:17:24 +00:00
|
|
|
// Register weatherSocket
|
|
|
|
const weatherSocket = new Socket(server);
|
|
|
|
Sockets.registerSocket('weather', weatherSocket);
|
2021-05-10 15:47:26 +00:00
|
|
|
|
2021-05-19 15:17:24 +00:00
|
|
|
server.listen(PORT, () => {
|
2021-06-07 11:40:51 +00:00
|
|
|
console.log(`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`);
|
2021-05-06 17:03:31 +00:00
|
|
|
})
|