-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (41 loc) · 1.2 KB
/
app.js
File metadata and controls
56 lines (41 loc) · 1.2 KB
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
const express = require('express');
const exphbs = require('express-handlebars');
const bodyParser = require('body-parser');
const path = require('path');
exports.exchangeWs = function (data) {
lastupdateWs.clients.forEach(function (client) {
client.send(JSON.stringify(data));
});
};
var exchanges = require('./exchanges/main');
var expressWs = require('express-ws')
expressWs = expressWs(express());
var app = expressWs.app;
app.ws('/exchangeWs', function (ws, req) {});
lastupdateWs = expressWs.getWss('/exchangeWs');
// Load routes
const stream = require('./routes/stream').router;
// Handlebars Middleware
app.engine('handlebars', exphbs({
defaultLayout: 'main'
}));
app.set('view engine', 'handlebars');
// Body parser middleware
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
// Static folder
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.redirect('/stream/index');
});
app.get('', (req, res) => {
res.redirect('/stream/index');
});
app.use('/stream', stream);
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
exchanges.init();
});