Comments (4)
@espositofulvio
I've fixed this issue, you can now use either '/'
or ''
as the route_prefix argument and both will work the same. This issue was actually also present when using Sanic-Dispatcher the conventional way (not using host-based routing) but it was not as obvious because routes still worked.
Version 0.5.4.2 has been released with this fix.
Also fixed:
You can now do host-based routing on any port, you don't have to use port 80.
from sanic-dispatcher.
I've found a fix. You told me in (#1) to have the prefix '/' anyway but that doesn't work. The following works instead:
from sanic import Sanic
from sanic.response import text
from sanic_dispatcher import SanicDispatcherMiddlewareController
from sanic.exceptions import NotFound
app = Sanic( 'app' )
dispatcher = SanicDispatcherMiddlewareController( app )
child_app = Sanic( 'child' )
# note no prefix
dispatcher.register_sanic_application( child_app, '', [ 'www.test.it' ] )
child_app2 = Sanic( 'child2' )
# note no prefix
dispatcher.register_sanic_application( child_app2, '', [ 'www.test.com' ] )
child_child_app2 = Sanic( 'child_child')
child_dispatcher = SanicDispatcherMiddlewareController( child_app2 )
child_dispatcher.register_sanic_application( child_child_app2, '/test' )
@child_child_app2.route( '/test' )
async def hello_child( request ):
return text( 'hello from www.test.com/test/test')
@child_app.route( '/' )
async def hello( request ):
return text( 'Hello from www.test.it' )
@child_app2.route( '/' )
async def hello2( request ):
return text( 'Hello from www.test.com' )
@child_app2.route( '/test' )
async def hello_test( request ):
return text( 'Hello from www.test.com/test' )
app.run( host = '127.0.0.1', port = 80, debug = True )
from sanic-dispatcher.
Sorry for delayed response.
Thanks for debugging this to find the solution.
It is weird that having '/'
route did not work for you, because it works in my testing.
That is something I will have to fix in a future version.
from sanic-dispatcher.
If it may be of help, I'm using:
Sanic 0,5,4
Sanic-dispatcher 0.5.2.1
My hunch is that by using the '/' you register 'www.domain,com/' as the app's prefix, but when you look for a prefix in the request's url such as ' www.domain.com/test ', something like the following happens:
- first you try www.domain.com/test and it doesn't match
- then you rsplit on '/' and you have www.domain.com and test as result
- then you try www.domain.com, but we have www.domain.com/ as the prefix so it doesn't match either.
- at this point NotFound is returned.
for request like 'www.domain.com/', instead, I think the problem is that path_info is originally null, so you find an application but when you build the SanicCompactURL the path is init-ed from path_info (which is null) and then when the application routing kicks in it doesn't find a route for ''.
from sanic-dispatcher.
Related Issues (12)
- Proposal: Adding a DomainDispatcher HOT 4
- Allow websocket connections (e.g. python-socketio) on child app HOT 8
- request.get_args method fails when querying child app HOT 4
- Module not found errors on version 0.7.0
- Will this be updated to be compatible with sanic 21.3.X+? HOT 5
- Does not work with Sanic 22.12.0 HOT 2
- Add unregister_application HOT 2
- Sanic-to-WSGI adapter Example HOT 4
- url_for and dispatched application HOT 4
- Gino not initalized error when using SanicDispatcherMiddlewareController HOT 4
- Can't dispatch a CORS-enabled Sanic application HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic-dispatcher.