-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
57 lines (45 loc) · 1.7 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require('dotenv').config()
// Constants
const express = require('express')
const env = process.env.NODE_ENV || 'development'
const PORT = process.env.PORT || 8080
const HOST = 'localhost'
const TIME_OF_DEATH = '2019/01/14'
const TIME_OF_DEAD_DEAD = '2019/07/17 00:00:00'
// App
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
if (env === 'development') {
const webpackConfig = require('./config/webpack.config')(env)
const compiler = require('webpack')(webpackConfig)
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: '/',
}))
app.use(require('webpack-hot-middleware')(compiler, {
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000
}))
// app.use(require('webpack-hot-middleware')(compiler))
} else {
app.use(express.static(`${__dirname}/build`))
}
app.use(express.static(`${__dirname}/public`))
const getDistance = () => {
// Set the date we're counting from
const countFromDate = new Date(TIME_OF_DEATH).getTime()
// Get todays date and time
const now = new Date(TIME_OF_DEAD_DEAD).getTime()
// Find the distance between now and the date from
const distance = now - countFromDate
// Time calculations for days, hours, minutes and seconds
const days = Math.floor(distance / (1000 * 60 * 60 * 24))
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60))
const seconds = Math.floor((distance % (1000 * 60)) / 1000)
return [days, hours, minutes, seconds]
}
setInterval(()=>{
io.emit('getDistance', getDistance())
}, 1000)
server.listen(PORT, HOST)
console.log(`Running on http://${HOST}:${PORT}`)