Skip to content

Commit 43cf5c2

Browse files
author
David Norman
committed
Use the squeezed instead of Apache for the web page serving
1 parent 69240c8 commit 43cf5c2

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

controller/scripts/squeezed

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# Start/stop the squeezelite daemon.
3+
#
4+
### BEGIN INIT INFO
5+
# Provides: squeezed
6+
# Required-Start: $squeezelite
7+
# Required-Stop:
8+
# Should-Start:
9+
# Should-Stop:
10+
# Default-Start: 2 3 4 5
11+
# Default-Stop: 0 1 6
12+
# Short-Description: Squeezebox server proxy
13+
# Description: An HTTP proxy for an external squeezebox server
14+
### END INIT INFO
15+
16+
PATH=/sbin
17+
DESC="squeezed daemon"
18+
NAME=squeezed
19+
DAEMON=/usr/local/bin/squeezed
20+
SCRIPTNAME=/etc/init.d/"$NAME"
21+
22+
test -f $DAEMON || exit 0
23+
24+
. /lib/lsb/init-functions
25+
26+
case "$1" in
27+
start) start-stop-daemon --start --quiet --background --oknodo --name $NAME --exec $DAEMON
28+
;;
29+
stop) start-stop-daemon --stop --quiet --oknodo --name $NAME
30+
;;
31+
*) log_action_msg "Usage: /etc/init.d/squeezed {start|stop}"
32+
exit 2
33+
;;
34+
esac
35+
exit 0

controller/src/squeezed

+19-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
import requests
44
import cherrypy
5-
import cherrypy_cors
65
import json
76
import socket
87
import sys
98

10-
cherrypy_cors.install()
11-
129
squeeze_player = ""
1310

1411
def get_ip_address():
@@ -20,25 +17,31 @@ def squeeze_request(params):
2017
js = {"id":1,"method":"slim.request","params":[squeeze_player,params]}
2118
return requests.post('http://192.168.0.101:9001/jsonrpc.js', data=json.dumps(js)).json()['result']
2219

23-
class SqueezeServerService(object):
20+
class Root(object):
21+
exposed = True
22+
23+
class Api(object):
2424
exposed = True
2525

2626
@cherrypy.tools.json_out()
2727
@cherrypy.tools.json_in()
2828
def POST(self):
2929
return squeeze_request(cherrypy.request.json)
3030

31-
@cherrypy_cors.tools.preflight(allowed_methods=["POST"])
32-
def OPTIONS(self):
33-
pass
34-
3531
if __name__ == '__main__':
36-
conf = {
32+
conf_api = {
3733
'/': {
3834
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
3935
'tools.response_headers.on': True,
4036
'tools.response_headers.headers': [('Content-Type', 'application/json')],
41-
'cors.expose.on': True,
37+
}
38+
}
39+
40+
conf_root = {
41+
'/': {
42+
'tools.staticdir.on': True,
43+
'tools.staticdir.dir': "/var/www",
44+
'tools.staticdir.index': "index.html"
4245
}
4346
}
4447

@@ -60,7 +63,11 @@ if __name__ == '__main__':
6063
sys.exit(0)
6164

6265
cherrypy.server.socket_host = "0.0.0.0"
63-
cherrypy.server.socket_port = 3000
66+
cherrypy.server.socket_port = 80
67+
68+
cherrypy.tree.mount(Root(), '/', conf_root)
69+
cherrypy.tree.mount(Api(), '/api', conf_api)
6470

65-
cherrypy.quickstart(SqueezeServerService(), '/', conf)
71+
cherrypy.engine.start()
72+
cherrypy.engine.block()
6673

web/src/js/slim-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function SlimClient($http, $location, serverStatus) {
22

33
var slimRequest = function(data) {
4-
return $http.post("http://" + $location.host() + ":3000/", data).
4+
return $http.post("http://" + $location.host() + "/api", data).
55
success(function(_, status) {
66
serverStatus.available = true;
77
}).

0 commit comments

Comments
 (0)