Pyjoyment.Plugin.Mount - Application mount plugin¶
# Pyjoyment
route = app.plugin('Mount', {'/prefix': '/home/sri/foo/script/foo'})
# Pyjoyment.Lite
route = plugin('Mount', {'/prefix': '/home/sri/myapp.py'})
# Adjust the generated route and mounted application
example = plugin('Mount', {'/example': '/home/sri/example.py'})
example.to(message='It works great!')
embedded = example.pattern.defaults['app']
embedded.config(foo='bar')
embedded.log = app.log
# Mount application with host
plugin('Mount', {'example.com': '/home/sri/myapp.py'})
# Host and path
plugin('Mount', {'example.com/myapp': '/home/sri/myapp.py'})
# Or even hosts with wildcard subdomains
plugin('Mount', {'*.example.com/myapp': '/home/sri/myapp.py'})
# Application object
plugin('Mount', {'/prefix': MyApp.new()})
# WSGI application, as an object or as the name of its module and its
# attribute
plugin('Mount', {'/flask': flask_app})
plugin('Mount', {'/flask': 'myflask:app'})
# ASGI application, as an object or as the name of its module and its
# attribute
plugin('Mount', {'/starlette': starlette_app})
plugin('Mount', {'/starlette': 'mystarlette:app'})
# FastCGI application, as PHP on php-fpm, by its location, with the
# directory of its scripts and the one entry of every other path
plugin('Mount', {'/php': 'fcgi://127.0.0.1:9000'})
plugin('Mount', {'/php': 'fcgi+unix://%2Frun%2Fphp%2Ffpm.sock'})
plugin('Mount', {'/blog': 'fcgi://127.0.0.1:9000?document_root=%2Fvar%2Fwww&script=index.php'})
# CGI application, as an object, as a string is the path of a script
plugin('Mount', {'/cgi-bin': Pyjo.App.CGI.new(document_root='/usr/lib/cgi-bin')})
# Event function of AWS Lambda, as an object, in a process of its own
plugin('Mount', {'/function': Pyjo.App.Lambda.new(function='myfunction.handler')})
# A regular expression of the whole path, whose group path is the rest of
# the path for the application, and whose other named groups are captures
plugin('Mount', {re.compile(r'/php(?P<path>/.*)?'): flask_app})
plugin('Mount', {re.compile(r'/(?P<user>\w+)/blog(?P<path>/.*)?'): flask_app})
Pyjoyment.Plugin.Mount is a plugin that allows you to mount whole
Pyjoyment applications, other applications of Pyjo, WSGI
applications, which Pyjo.App.WSGI runs, and ASGI applications,
whose __call__ is a coroutine function, which Pyjo.App.ASGI runs,
as an application of Pyjo from a script, an object, or the name of a
module and its attribute, and FastCGI applications, which
Pyjo.App.FastCGI connects to, by their location fcgi:// or
fcgi+unix://, CGI programs, which Pyjo.App.CGI runs, and
event functions of AWS Lambda, which Pyjo.App.Lambda runs, as an
object of them. An application that is not one of Pyjoyment gets the
server that runs it with server() before the server
starts, as the application that mounts it does.
The path is a pattern of a route that matches the beginning of the path of a
request, as in Mojolicious, so that /php matches /php.css too, which
an application of another framework does not get, as its SCRIPT_NAME or
root_path ends at a slash. A regular expression matches the whole path, as
the ones of PromQL do, with the rest of it for the application in its group
path.
The code of this plugin is a good example for learning to build new plugins, you’re welcome to fork it.
See Pyjoyment.Plugins for a list of plugins that are available by
default.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojolicious::Plugin::Mount of Mojolicious 9.49.
Classes¶
- class Pyjoyment.Plugin.Mount.Pyjoyment_Plugin_Mount[source]¶
Pyjoyment.Plugin.Mountinherits all methods fromPyjoyment.Pluginand implements the following new ones.- register(app: Pyjoyment_App, conf: dict[Any, Any]) Pyjoyment_Routes_Route[source]¶
route = plugin.register(Pyjoyment.new(), {'/foo': '/some/app.py'}) route = plugin.register(Pyjoyment.new(), {'/foo': 'some_app:app'})
Mount application and return the generated route, which is usually a
Pyjoyment.Routes.Routeobject.