This repository has been archived by the owner on May 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (42 loc) · 1.4 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var fs = require('fs')
var child_process = require('child_process')
var indexRouter = require('./routes/index');
var totemRouter = require('./routes/totem');
var gestioneRouter = require('./routes/gestione');
var qrRouter = require('./routes/qr')
var slideshow = require('./routes/slideshow')
var app = express();
var standardConfig = {
'startCommand': 'chromium',
'enabled': false,
'endpoint': 'https://example.com',
'token': 'token-di-esempio',
'marquee': '⇨ Accedi al pannello di gestione per configurare il totem ⇦'
}
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
var totem = {}
if(!fs.existsSync(__dirname + '/config.json')) {
totem = standardConfig
fs.writeFileSync(__dirname + '/config.json', JSON.stringify(standardConfig))
} else {
totem = JSON.parse(fs.readFileSync(__dirname + '/config.json'))
}
try {
child_process.exec(totem.startCommand + ' --kiosk --app="http://localhost:3000"')
} catch(e) {
console.log(e)
}
app.use('/', indexRouter);
app.use('/totem', totemRouter);
app.use('/gestione', gestioneRouter);
app.use('/qr', qrRouter);
app.use('/slideshow', slideshow);
module.exports = app;