diff --git a/Makefile b/Makefile index 3332f13..f8de34e 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ root/js/solardash.file.js: root/js/solardash.base.js root/js/solardash.https.js: root/js/solardash.base.js all: $(JSFILES) +run: $(JSFILES) .jspp.js: cpp -Wno-invalid-pp-token -E $< | sed -e '/^#/d' > $@ || (rm "$@"; false) @@ -39,5 +40,8 @@ test: test-noentr: python -m coverage run -m unittest $(PROJNAME) && coverage report --omit=p/\* -m -i +run: $(JSFILES) + python -m aiohttp.web -H localhost -P 38382 solardash:getapp p/src/raineagle/fixtures/data + env: ($(VIRTUALENV) $(VIRTUALENVARGS) p && . ./p/bin/activate && pip install -r requirements.txt) diff --git a/root/js/solardash.https.jspp b/root/js/solardash.https.jspp index 6cc552d..b80070f 100644 --- a/root/js/solardash.https.jspp +++ b/root/js/solardash.https.jspp @@ -1,3 +1,8 @@ -var socket = new WebSocket('wss://' + location.host + '/solar.ws'); +// Make sure you're editing the jspp file +var wsproto = 'wss:'; +if (document.location.protocol == 'http:') + wsproto = 'ws:'; + +var socket = new WebSocket(wsproto + '//' + location.host + '/solar.ws'); #include "solardash.base.js" diff --git a/solardash/__init__.py b/solardash/__init__.py index 3e577f6..93563e6 100644 --- a/solardash/__init__.py +++ b/solardash/__init__.py @@ -71,13 +71,11 @@ class SolarDataWS(object): def get_routes(self): return [ - web.get('/ws', self.websocket_handler), + web.get('/solar.ws', self.websocket_handler), ] -# XXX - how to configure this properly -sdws = SolarDataWS('./raineagle.') - -def getapp(sdws): +def getapp(argv): + sdws = SolarDataWS(argv[0]) app = web.Application() app.add_routes(sdws.get_routes()) p = os.path.join(os.path.dirname(__file__), '..', 'root') @@ -91,7 +89,9 @@ def getapp(sdws): return app -app = getapp(sdws) +def main(): + app = getapp(sys.argv[1:]) + web.run_app(app) # https://stackoverflow.com/questions/23033939/how-to-test-python-3-4-asyncio-code # Slightly modified to timeout and to print trace back when canceled. @@ -124,9 +124,8 @@ class Test(unittest.TestCase): self.rootdir = os.path.join(os.path.dirname(__file__), '..', 'root') os.chdir(self.tempdir) - sdws = SolarDataWS(os.path.join(self.tempdir, 'raineagle')) - app = getapp(sdws) + app = getapp([ os.path.join(self.tempdir, 'raineagle') ]) self._app = app # launch the server @@ -173,7 +172,7 @@ class Test(unittest.TestCase): r = [] try: async with aiohttp.ClientSession() as session, \ - session.ws_connect(self.makeurl('ws')) as ws: + session.ws_connect(self.makeurl('solar.ws')) as ws: async for msg in ws: r.append(msg) if len(r) == 2: