Code Monkey home page Code Monkey logo

Comments (4)

ashleysommer avatar ashleysommer commented on June 14, 2024 1

@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.

espositofulvio avatar espositofulvio commented on June 14, 2024

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.

ashleysommer avatar ashleysommer commented on June 14, 2024

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.

espositofulvio avatar espositofulvio commented on June 14, 2024

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:

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.