From 8aee12fee3aee0bd85068822a3d5df50f6bc5c84 Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Sat, 8 Apr 2017 12:05:39 -0400 Subject: [PATCH] move some settings into a config file --- .gitignore | 4 ++++ config.json.sample | 5 +++++ player.js | 21 +++++++++++++-------- run-tag-reader | 3 --- source/templates/default.pug | 3 ++- source/templates/homepage.pug | 5 +++++ static/jukebox.js | 2 +- 7 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 config.json.sample delete mode 100755 run-tag-reader diff --git a/.gitignore b/.gitignore index 2b7d7e2..fc499ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ node_modules lib +config.json + +npm-debug.log + media/* !media/.do_not_delete diff --git a/config.json.sample b/config.json.sample new file mode 100644 index 0000000..5e348fa --- /dev/null +++ b/config.json.sample @@ -0,0 +1,5 @@ +{ + "port": "80", + "tag_reader": ["./lib/bin/python", "tag-reader.py"], + "mpg321": ["/usr/bin/mpg321", "-R", "-"] +} diff --git a/player.js b/player.js index f8a5432..232ef13 100644 --- a/player.js +++ b/player.js @@ -1,7 +1,10 @@ + +const config = require('./config.json') + const glob = require('glob'); const spawn = require('child_process').spawn; -const tag_reader = spawn('/home/annika/rfid/run-tag-reader'); -const player = spawn('/usr/bin/mpg321', ['-R', '-']); +const tag_reader = spawn(config.tag_reader[0], config.tag_reader.slice(1)); +const player = spawn(config.mpg321[0], config.mpg321.slice(1)); const express = require('express'); const logger = require('morgan') @@ -130,9 +133,10 @@ app.use(express.static(__dirname + '/static')) app.get('/', function (req, res, next) { try { var html = template({ - title: 'Home', - last_tag: last_tag, - play_log: play_log + title: 'Home' + , last_tag: last_tag + , play_log: play_log + , config: config }) res.send(html) } catch (e) { @@ -157,7 +161,8 @@ wss.on('connection', function (ws) { server.on('request', app); -var server_port = process.env.PORT || 80; -server.listen(server_port, function () { - console.log('[http] listening on http://localhost:' + server_port) +server.listen(config.port, function () { + console.log('[http] listening on http://localhost:' + config.port) }) + +// vim:ts=2 sw=2 et: diff --git a/run-tag-reader b/run-tag-reader deleted file mode 100755 index aa614c8..0000000 --- a/run-tag-reader +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -sudo -n /home/annika/rfid/lib/bin/python tag-reader.py diff --git a/source/templates/default.pug b/source/templates/default.pug index 90ffe08..84f1030 100644 --- a/source/templates/default.pug +++ b/source/templates/default.pug @@ -3,7 +3,6 @@ html head link(rel='stylesheet', href='/css/index.css') title jukebox.stop.wtf - script(src='/jukebox.js') body .header h1.page-title jukebox.stop.wtf @@ -19,3 +18,5 @@ html .footer p made with love by annika + + script(src='/jukebox.js') diff --git a/source/templates/homepage.pug b/source/templates/homepage.pug index 08b5849..d7e9b2f 100644 --- a/source/templates/homepage.pug +++ b/source/templates/homepage.pug @@ -6,3 +6,8 @@ block content span#last_tag #{last_tag} ul#play-log include log + + script. + var jukebox = { + port: #{config.port} + } diff --git a/static/jukebox.js b/static/jukebox.js index 9fbf13d..44b4d7d 100644 --- a/static/jukebox.js +++ b/static/jukebox.js @@ -10,7 +10,7 @@ window.onload = function() { } var host = window.document.location.host.replace(/:.*/, ''); - var ws = new WebSocket('ws://' + host + ':80'); + var ws = new WebSocket('ws://' + host + ':' + jukebox.port); ws.onmessage = function (event) { console.log(event.data); updateLog(JSON.parse(event.data));