-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 991 Bytes
/
app.js
File metadata and controls
44 lines (37 loc) · 991 Bytes
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
const http = require('http')
const express = require('express')
const morgan = require('morgan')
const parser = require('body-parser')
const bonjour = require('bonjour')()
const config = require('./config')
const logger = require('./lib/logger')
const app = express()
const server = http.Server(app)
const api = require('./lib')
const PORT = config.PORT || 9487
// for the future
const env = process.env.NODE_ENV || 'development'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
app
.use( morgan('combined') )
.use( express.static(`${__dirname}/panel/dist`) )
.use( parser.urlencoded({ extended: true }) )
// api layer
.use('/api', api.router)
server
.listen(PORT, err => {
if (err)
throw err
logger.info(`Server listening on port ${PORT}.`)
// advertise an HTTP server
bonjour.publish({
name: 'Card Reader Server',
host: 'vote.local',
type: 'http',
port: PORT
})
})
api.io.attach(server, {
pingTimeout: 2000,
pingInterval: 5000
})