Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 1, 2023
1 parent 147a826 commit 1b21723
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ async def redirect_reference_to_documentation(request: Request,
return RedirectResponse('/documentation')
return await call_next(request)

# NOTE in our global fly.io deployment we need to make sure that we connect back to the same instance.
# NOTE In our global fly.io deployment we need to make sure that we connect back to the same instance.
fly_instance_id = os.environ.get('FLY_ALLOC_ID', 'local').split('-')[0]
nicegui_globals.socket_io_js_extra_headers['fly-force-instance-id'] = fly_instance_id # for http long polling
nicegui_globals.socket_io_js_extra_headers['fly-force-instance-id'] = fly_instance_id # for HTTP long polling
nicegui_globals.socket_io_js_query_params['fly_instance_id'] = fly_instance_id # for websocket (FlyReplayMiddleware)


class FlyReplayMiddleware(BaseHTTPMiddleware):
"""
If the wrong instance was picked by the fly.io load balancer we use the fly-replay header
"""Replay to correct fly.io instance.
If the wrong instance was picked by the fly.io load balancer, we use the fly-replay header
to repeat the request again on the right instance.
This only works if the correct instance is provided as a query_string parameter.
Expand Down
3 changes: 1 addition & 2 deletions nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ def __exit__(self, *_):
def build_response(self, request: Request, status_code: int = 200) -> Response:
prefix = request.headers.get('X-Forwarded-Prefix', request.scope.get('root_path', ''))
elements = json.dumps({id: element._to_dict() for id, element in self.elements.items()})
socket_io_js_query_params = {**globals.socket_io_js_query_params, **{'client_id': self.id}}
socket_io_js_query_params = {**globals.socket_io_js_query_params, 'client_id': self.id}
vue_html, vue_styles, vue_scripts, imports, js_imports = generate_resources(prefix, self.elements.values())
return templates.TemplateResponse('index.html', {
'request': request,
'version': __version__,
'client_id': str(self.id),
'elements': elements,
'head_html': self.head_html,
'body_html': '<style>' + '\n'.join(vue_styles) + '</style>\n' + self.body_html + '\n' + '\n'.join(vue_html),
Expand Down
2 changes: 1 addition & 1 deletion nicegui/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class State(Enum):
air: Optional['Air'] = None
socket_io_js_query_params: Dict = {}
socket_io_js_extra_headers: Dict = {}
# NOTE we favour websocket over polling
# NOTE we favor websocket over polling
socket_io_js_transports: List[Literal['websocket', 'polling']] = ['websocket', 'polling']

_socket_id: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion nicegui/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
},
connect_error: (err) => {
if (err.message == 'timeout') {
console.log('reloading because connection time out')
console.log('reloading because connection timed out')
window.location.reload(); // see https://github.com/zauberzeug/nicegui/issues/198
}
},
Expand Down

0 comments on commit 1b21723

Please sign in to comment.