Move control socket
This commit is contained in:
parent
48701890df
commit
bc8b805b2f
33
app.js
33
app.js
|
@ -1,4 +1,5 @@
|
|||
var express = require('express'),
|
||||
const
|
||||
express = require('express'),
|
||||
app = module.exports = express(),
|
||||
server = require('http').createServer(app),
|
||||
Stopwatch = require('./models/stopwatch'),
|
||||
|
@ -30,7 +31,9 @@ var host = process.env.HOST || '0.0.0.0';
|
|||
server.listen(port, host, function() {
|
||||
console.log("Express server listening on %j in %s mode", server.address(), app.settings.env);
|
||||
});
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
|
||||
stopwatch.on('tick:stopwatch', function(time) {
|
||||
io.sockets.emit('time', { time: time });
|
||||
});
|
||||
|
@ -75,43 +78,41 @@ app.get('/', function(req, res) {
|
|||
res.render('index', { title: process.env.TITLE });
|
||||
});
|
||||
|
||||
app.get('/control/', function(req, res) {
|
||||
|
||||
const control = express.Router();
|
||||
|
||||
control.get('/', function(req, res) {
|
||||
res.render('control', { title: process.env.TITLE });
|
||||
});
|
||||
|
||||
app.post('/reset/', function (req, res) {
|
||||
control.post('/reset/', function (req, res) {
|
||||
stopwatch.reset();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/reset-short/', function (req, res) {
|
||||
control.post('/reset-short/', function (req, res) {
|
||||
stopwatch.resetShort();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/start-from-reset/', function (req, res) {
|
||||
control.post('/start-from-reset/', function (req, res) {
|
||||
stopwatch.reset();
|
||||
stopwatch.start();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/start-from-reset-short/', function (req, res) {
|
||||
control.post('/start-from-reset-short/', function (req, res) {
|
||||
stopwatch.resetShort();
|
||||
stopwatch.start();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/start/', function (req, res) {
|
||||
control.post('/start/', function (req, res) {
|
||||
stopwatch.start();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/stop/', function (req, res) {
|
||||
control.post('/stop/', function (req, res) {
|
||||
stopwatch.stop();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.post('/zero/', function (req, res) {
|
||||
control.post('/zero/', function (req, res) {
|
||||
stopwatch.zero();
|
||||
res.send("OK");
|
||||
});
|
||||
|
||||
app.use('/control', control);
|
Loading…
Reference in New Issue