move some settings into a config file

This commit is contained in:
Annika Backstrom 2017-04-08 12:05:39 -04:00
parent 1636bffd71
commit 8aee12fee3
7 changed files with 30 additions and 13 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
node_modules
lib
config.json
npm-debug.log
media/*
!media/.do_not_delete

5
config.json.sample Normal file
View File

@ -0,0 +1,5 @@
{
"port": "80",
"tag_reader": ["./lib/bin/python", "tag-reader.py"],
"mpg321": ["/usr/bin/mpg321", "-R", "-"]
}

View File

@ -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:

View File

@ -1,3 +0,0 @@
#!/bin/bash
sudo -n /home/annika/rfid/lib/bin/python tag-reader.py

View File

@ -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')

View File

@ -6,3 +6,8 @@ block content
span#last_tag #{last_tag}
ul#play-log
include log
script.
var jukebox = {
port: #{config.port}
}

View File

@ -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));