-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (30 loc) · 977 Bytes
/
index.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
require("dotenv").config()
const path = require('path')
const http = require('http')
const express = require('express');
const app = express();
const applyRoute = require('./routers/routes')
const applyMidleware = require('./middlewares/midlewares');
const dbConnection = require("./config/dbConnection");
const sheduleTask = require("./utils/sheduleTask");
const initSocket = require("./config/socket");
app.use(express.static(path.join(__dirname,'public')))
app.use(express.static(path.join(__dirname, 'client/dist')))
//create http server
const server = http.createServer(app)
//all midlewares apply
applyMidleware(app)
//all routes apply
applyRoute(app)
//connect database
dbConnection()
//socket initialize
initSocket(server)
// app server initialzed
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,'client/dist/index.html'))
})
sheduleTask()
server.listen(process.env.PORT || 8080,()=>{
console.log('Express server listening on port 8080')
})