move some settings into a config file
This commit is contained in:
parent
1636bffd71
commit
8aee12fee3
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,8 @@
|
|||||||
node_modules
|
node_modules
|
||||||
lib
|
lib
|
||||||
|
config.json
|
||||||
|
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
media/*
|
media/*
|
||||||
!media/.do_not_delete
|
!media/.do_not_delete
|
||||||
|
5
config.json.sample
Normal file
5
config.json.sample
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"port": "80",
|
||||||
|
"tag_reader": ["./lib/bin/python", "tag-reader.py"],
|
||||||
|
"mpg321": ["/usr/bin/mpg321", "-R", "-"]
|
||||||
|
}
|
21
player.js
21
player.js
@ -1,7 +1,10 @@
|
|||||||
|
|
||||||
|
const config = require('./config.json')
|
||||||
|
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const tag_reader = spawn('/home/annika/rfid/run-tag-reader');
|
const tag_reader = spawn(config.tag_reader[0], config.tag_reader.slice(1));
|
||||||
const player = spawn('/usr/bin/mpg321', ['-R', '-']);
|
const player = spawn(config.mpg321[0], config.mpg321.slice(1));
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('morgan')
|
const logger = require('morgan')
|
||||||
@ -130,9 +133,10 @@ app.use(express.static(__dirname + '/static'))
|
|||||||
app.get('/', function (req, res, next) {
|
app.get('/', function (req, res, next) {
|
||||||
try {
|
try {
|
||||||
var html = template({
|
var html = template({
|
||||||
title: 'Home',
|
title: 'Home'
|
||||||
last_tag: last_tag,
|
, last_tag: last_tag
|
||||||
play_log: play_log
|
, play_log: play_log
|
||||||
|
, config: config
|
||||||
})
|
})
|
||||||
res.send(html)
|
res.send(html)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -157,7 +161,8 @@ wss.on('connection', function (ws) {
|
|||||||
|
|
||||||
server.on('request', app);
|
server.on('request', app);
|
||||||
|
|
||||||
var server_port = process.env.PORT || 80;
|
server.listen(config.port, function () {
|
||||||
server.listen(server_port, function () {
|
console.log('[http] listening on http://localhost:' + config.port)
|
||||||
console.log('[http] listening on http://localhost:' + server_port)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// vim:ts=2 sw=2 et:
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
sudo -n /home/annika/rfid/lib/bin/python tag-reader.py
|
|
@ -3,7 +3,6 @@ html
|
|||||||
head
|
head
|
||||||
link(rel='stylesheet', href='/css/index.css')
|
link(rel='stylesheet', href='/css/index.css')
|
||||||
title jukebox.stop.wtf
|
title jukebox.stop.wtf
|
||||||
script(src='/jukebox.js')
|
|
||||||
body
|
body
|
||||||
.header
|
.header
|
||||||
h1.page-title jukebox.stop.wtf
|
h1.page-title jukebox.stop.wtf
|
||||||
@ -19,3 +18,5 @@ html
|
|||||||
|
|
||||||
.footer
|
.footer
|
||||||
p made with love by annika
|
p made with love by annika
|
||||||
|
|
||||||
|
script(src='/jukebox.js')
|
||||||
|
@ -6,3 +6,8 @@ block content
|
|||||||
span#last_tag #{last_tag}
|
span#last_tag #{last_tag}
|
||||||
ul#play-log
|
ul#play-log
|
||||||
include log
|
include log
|
||||||
|
|
||||||
|
script.
|
||||||
|
var jukebox = {
|
||||||
|
port: #{config.port}
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ window.onload = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var host = window.document.location.host.replace(/:.*/, '');
|
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) {
|
ws.onmessage = function (event) {
|
||||||
console.log(event.data);
|
console.log(event.data);
|
||||||
updateLog(JSON.parse(event.data));
|
updateLog(JSON.parse(event.data));
|
||||||
|
Loading…
Reference in New Issue
Block a user