Fix ASGI websockets when serving on sub-path under site root
This commit is contained in:
parent
a95cc2b9e8
commit
7fa39d42e2
|
@ -5,6 +5,9 @@ CHANGELOG
|
|||
Unreleased
|
||||
----------
|
||||
|
||||
* Fix ASGI websockets when serving on sub-path under site root.
|
||||
|
||||
|
||||
0.9.94 (2024-04-16)
|
||||
-------------------
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
# Copyright © 2010-2024 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,14 +24,10 @@
|
|||
ASGI App Utilities
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
import configparser
|
||||
import logging
|
||||
|
||||
import six
|
||||
from six.moves import configparser
|
||||
|
||||
from rattail.util import load_object
|
||||
|
||||
from asgiref.wsgi import WsgiToAsgi
|
||||
|
@ -49,6 +45,12 @@ class TailboneWsgiToAsgi(WsgiToAsgi):
|
|||
protocol = scope['type']
|
||||
path = scope['path']
|
||||
|
||||
# strip off the root path, if non-empty. needed for serving
|
||||
# under /poser or anything other than true site root
|
||||
root_path = scope['root_path']
|
||||
if root_path and path.startswith(root_path):
|
||||
path = path[len(root_path):]
|
||||
|
||||
if protocol == 'websocket':
|
||||
websockets = self.wsgi_application.registry.get(
|
||||
'tailbone_websockets', {})
|
||||
|
@ -85,7 +87,7 @@ def make_asgi_app(main_app=None):
|
|||
# parse the settings needed for pyramid app
|
||||
settings = dict(parser.items('app:main'))
|
||||
|
||||
if isinstance(main_app, six.string_types):
|
||||
if isinstance(main_app, str):
|
||||
make_wsgi_app = load_object(main_app)
|
||||
elif callable(main_app):
|
||||
make_wsgi_app = main_app
|
||||
|
|
Loading…
Reference in a new issue