Skip to content

Commit 67b26a9

Browse files
committed
to latest livereload-js version, aux ssl support
1 parent 0880b35 commit 67b26a9

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

aiohttp_devtools/runserver/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def runserver(**config_kwargs: Any) -> RunServer:
3232
# force a full reload in sub processes so they load an updated version of code, this must be called only once
3333
set_start_method('spawn')
3434
config = Config(**config_kwargs)
35-
config.import_module()
35+
module = config.import_module()
36+
ssl_context = config.get_ssl_context(module)
3637

3738
asyncio.run(check_port_open(config.main_port, host=config.bind_address))
3839

@@ -50,15 +51,15 @@ def runserver(**config_kwargs: Any) -> RunServer:
5051
logger.debug('starting livereload to watch %s', config.static_path_str)
5152
aux_app.cleanup_ctx.append(static_manager.cleanup_ctx)
5253

53-
url = 'http://{0.host}:{0.aux_port}'.format(config)
54+
url = '{0.protocol}://{0.host}:{0.aux_port}'.format(config)
5455
logger.info('Starting aux server at %s ◆', url)
5556

5657
if config.static_path:
5758
rel_path = config.static_path.relative_to(os.getcwd())
5859
logger.info('serving static files from ./%s/ at %s%s', rel_path, url, config.static_url)
5960

6061
return {"app": aux_app, "host": config.bind_address, "port": config.aux_port,
61-
"shutdown_timeout": 0.01, "access_log_class": AuxAccessLogger, "ssl_context": None}
62+
"shutdown_timeout": 0.01, "access_log_class": AuxAccessLogger, "ssl_context": ssl_context}
6263

6364

6465
def serve_static(*, static_path: str, livereload: bool = True, bind_address: str = "localhost", port: int = 8000,

aiohttp_devtools/runserver/serve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
except ImportError:
3333
static_root_key = None # type: ignore[assignment]
3434

35-
LIVE_RELOAD_HOST_SNIPPET = '\n<script src="http://{}:{}/livereload.js"></script>\n'
35+
LIVE_RELOAD_HOST_SNIPPET = '\n<script src="{}://{}:{}/livereload.js"></script>\n'
3636
LIVE_RELOAD_LOCAL_SNIPPET = b'\n<script src="/livereload.js"></script>\n'
3737

3838
LAST_RELOAD = web.AppKey("LAST_RELOAD", List[float])
@@ -84,7 +84,7 @@ async def on_prepare(request: web.Request, response: web.StreamResponse) -> None
8484
or request.path.startswith("/_debugtoolbar")
8585
or "text/html" not in response.content_type):
8686
return
87-
lr_snippet = LIVE_RELOAD_HOST_SNIPPET.format(get_host(request), config.aux_port)
87+
lr_snippet = LIVE_RELOAD_HOST_SNIPPET.format(config.protocol, get_host(request), config.aux_port)
8888
dft_logger.debug("appending live reload snippet '%s' to body", lr_snippet)
8989
response.body += lr_snippet.encode()
9090
response.headers[CONTENT_LENGTH] = str(len(response.body))
@@ -105,7 +105,7 @@ async def no_cache_middleware(request: web.Request, handler: Handler) -> web.Str
105105
# we set the app key even in middleware to make the switch to production easier and for backwards compat.
106106
@web.middleware
107107
async def static_middleware(request: web.Request, handler: Handler) -> web.StreamResponse:
108-
static_url = 'http://{}:{}/{}'.format(get_host(request), config.aux_port, static_path)
108+
static_url = '{}://{}:{}/{}'.format(config.protocol, get_host(request), config.aux_port, static_path)
109109
dft_logger.debug('setting app static_root_url to "%s"', static_url)
110110
_change_static_url(request.app, static_url)
111111
return await handler(request)
@@ -126,7 +126,7 @@ def shutdown() -> NoReturn:
126126
config.protocol, config.host, config.main_port, path))
127127

128128
if config.static_path is not None:
129-
static_url = 'http://{}:{}/{}'.format(config.host, config.aux_port, static_path)
129+
static_url = '{}://{}:{}/{}'.format(config.protocol, config.host, config.aux_port, static_path)
130130
dft_logger.debug('settings app static_root_url to "%s"', static_url)
131131
_set_static_url(app, static_url)
132132

grablib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
download_root: 'aiohttp_devtools/runserver'
22
download:
3-
'GITHUB/livereload/livereload-js/v2.2.1/dist/livereload.js': '/'
3+
'GITHUB/livereload/livereload-js/v4.0.2/dist/livereload.js': '/'

tests/test_runserver_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ async def check_callback(session, ssl_context):
379379
text = await r.text()
380380
print(text)
381381
assert "<h1>hello world</h1>" in text
382-
assert '<script src="http://localhost:8001/livereload.js"></script>' in text
382+
assert '<script src="https://localhost:8001/livereload.js"></script>' in text
383383

384384
async with session.get("https://localhost:8000/error", ssl=ssl_context) as r:
385385
assert r.status == 500
@@ -392,8 +392,8 @@ async def check_callback(session, ssl_context):
392392
loop.run_until_complete(shutdown(aux_app))
393393
loop.run_until_complete(aux_app.cleanup())
394394
assert (
395-
"adev.server.dft INFO: Starting aux server at http://localhost:8001 ◆\n"
396-
"adev.server.dft INFO: serving static files from ./static_dir/ at http://localhost:8001/static/\n"
395+
"adev.server.dft INFO: Starting aux server at https://localhost:8001 ◆\n"
396+
"adev.server.dft INFO: serving static files from ./static_dir/ at https://localhost:8001/static/\n"
397397
"adev.server.dft INFO: Starting dev server at https://localhost:8000 ●\n"
398398
) in smart_caplog
399399
loop.run_until_complete(asyncio.sleep(.25)) # TODO(aiohttp 4): Remove this hack

tests/test_serve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def test_html_file_livereload(aiohttp_client, tmpworkdir):
6262
assert r.status == 200
6363
assert r.headers['content-type'] == 'application/javascript'
6464
text = await r.text()
65-
assert text.startswith('(function e(t,n,r){')
65+
assert text.startswith('(function(){function r(e,n,t)')
6666

6767

6868
async def test_serve_index(aiohttp_client, tmpworkdir):

0 commit comments

Comments
 (0)