-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (34 loc) · 1.16 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
const express = require('express');
const app = express();
const backendControl = require('./backendControl');
require('dotenv').config();
//adds option for redis
const redis = process.env.USE_REDIS ? require('redis').createClient(
{url:`redis://:${process.env.REDIS_AUTH}@localhost:6379`,}
) : undefined;
if (redis) {
redis.on('error', (err) => console.log('Redis Client Error', err));
if (process.env.REDIS_AUTH) {
console.log('authentication supplied.');
}
else {
console.warn('no auth supplied.');
}
redis.connect();
}
// Basic Middleware
app.use(express.static(__dirname + '/public'));
// svg Sprites from Font Awesome
app.use(express.static(__dirname + '/node_modules/@fortawesome/fontawesome-free/sprites'));
// Basic Routes
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/views/index.html');
});
//load svg sprites from font awesome
app.get('/fscreen.js', (req, res) => res.sendFile(__dirname + '/node_modules/fscreen/dist/fscreen.esm.js'));
// Start server
const server = app.listen(process.env.PORT, () => {
console.log(`Server listening on port: ${process.env.PORT}`);
});
const io = require('socket.io')(server);
backendControl(io,redis);