Comments (4)
I simply want to use Sanic behind gunicorn or Zappa or whatever WSGI server I want, nothing more. Can I do that with this?
What you need for that is a WSGI-to-Sanic adaptor, not a Sanic-to-WSGI adapter. Sanic-Dispatcher cannot do what you want in this case.
But good news! Sanic has recently been given its own gunicorn worker, which does do exactly what you are asking about.
See the deployment docs for how to use it: (See under "Running via Gunicorn")
https://github.com/channelcat/sanic/blob/master/docs/sanic/deploying.md#running-via-gunicorn
from sanic-dispatcher.
There are two trivial examples of usage of the Sanic-to-WSGI adapter already in the README.md file.
Any time you use the register_wsgi_application
to add an app to the dispatcher
you are telling the dispatcher to use the Sanic-to-WSGI adapter to run that invoke that application.
Copied from the README.md file:
What if the other App is a Flask App?
from flask import Flask, make_response
app = Sanic(__name__)
dispatcher = SanicDispatcherMiddlewareController(app)
flaskapp = Flask("MyFlaskApp")
# register the wsgi_app method from the flask app into the dispatcher
dispatcher.register_wsgi_application(flaskapp.wsgi_app, "/flaskprefix")
@flaskapp.route('/')
def index():
return make_response("Hello World from Flask App")
Browsing to url /flaskprefix/
will invoke the Flask App, and call the /
route which displays "Hello World from Flask App"
What if the other App is a Django App?
import my_django_app
app = Sanic(__name__)
dispatcher = SanicDispatcherMiddlewareController(app)
# register the django wsgi application into the dispatcher
dispatcher.register_wsgi_application(my_django_app.wsgi.application,
"/djangoprefix")
Browsing to url /djangoprefix/
will invoke the Django App.
from sanic-dispatcher.
In response to your question about a passthrough; Yes!, that is possible.
Just register your application using the route_prefix '/'
like so:
from flask import Flask, make_response
app = Sanic(__name__)
dispatcher = SanicDispatcherMiddlewareController(app)
flaskapp = Flask("MyFlaskApp")
# register the wsgi_app method from the flask app into the dispatcher
dispatcher.register_wsgi_application(flaskapp.wsgi_app, "/")
@flaskapp.route('/')
def index():
return make_response("Hello World from Flask App")
In this example specifying the prefix '/'
will cause all routes to be passed into the Flask application.
from sanic-dispatcher.
Closing due to no response in over 27 days.
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
- host based routing doesn't work 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.