-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
33 lines (26 loc) · 1.04 KB
/
app.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
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const path = require('path')
const socket = require('socket.io')
const getAllDataHandler = require('./routes/getAllAccountData.js')
const createWebhookHandler = require('./routes/webhook.js')
const app = express()
// MIDDLEWARE
app.use(express.static('public'))
app.use(bodyParser.urlencoded({ extended: false }))
// Allow cors from react dev-server
const corsWhiteList = ['http://localhost:3000']
app.use(cors({ origin: corsWhiteList }))
// Routes
app.get('/', (req, res) => res.sendFile(path.join(__dirname, './public/index.html')))
app.get('/get-all-account-data', getAllDataHandler)
const server = app.listen(process.env.PORT || 4000, () => {
console.log('Example app listening on port 4000!')
const io = socket(server, { origins: '*:*' })
const webhookHandler = createWebhookHandler({ socket: io })
app.post('/webhook', webhookHandler)
io.on('connection', (client) => {
console.log('client connected to socket', client)
})
})