Skip to content

Commit

Permalink
Ignore favicon requests. Output error to http stream if no system found
Browse files Browse the repository at this point in the history
  • Loading branch information
jishi committed Oct 9, 2016
1 parent 4c9b66f commit 952e01d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/sonos-http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const logger = require('sonos-discovery/lib/helpers/logger');

function HttpAPI(discovery, settings) {

var port = settings.port;
var webroot = settings.webroot;
var actionsDir = __dirname + '/actions';
var actions = {};
const port = settings.port;
const webroot = settings.webroot;
const actions = {};

this.getWebRoot = function () {
return webroot;
Expand Down Expand Up @@ -48,18 +47,23 @@ function HttpAPI(discovery, settings) {
});

this.requestHandler = function (req, res) {
if (discovery.zones.length === 0) {
res.writeHead(500, 'No system has been found yet.');
if (req.url === '/favicon.ico') {
res.end();
logger.error('No system has yet been discovered. Please see https://github.com/jishi/node-sonos-http-api/issues/77 if it doesn\'t resolve itself in a few seconds.');
return;
}

var params = req.url.substring(1).split('/');
if (discovery.zones.length === 0) {
const msg = 'No system has yet been discovered. Please see https://github.com/jishi/node-sonos-http-api/issues/77 if it doesn\'t resolve itself in a few seconds.';
logger.error(msg);
sendResponse(500, { status: 'error', error: msg });
return;
}

const params = req.url.substring(1).split('/');

var player = discovery.getPlayer(decodeURIComponent(params[0]));
let player = discovery.getPlayer(decodeURIComponent(params[0]));

var opt = {};
const opt = {};

if (player) {
opt.action = (params[1] || '').toLowerCase();
Expand Down

0 comments on commit 952e01d

Please sign in to comment.