diff --git a/evennia/game_template/server/conf/web_plugins.py b/evennia/game_template/server/conf/web_plugins.py new file mode 100644 index 000000000..eccda6ddd --- /dev/null +++ b/evennia/game_template/server/conf/web_plugins.py @@ -0,0 +1,29 @@ +""" +Web plugin hooks. +""" + + +def at_webserver_root_creation(web_root): + """ + This is called as the web server has finished building its default + path tree. At this point, the media/ and static/ URIs have already + been added to the web root. + + Args: + web_root (twisted.web.resource.Resource): The root + resource of the URI tree. Use .putChild() to + add new subdomains to the tree. + + Returns: + web_root (twisted.web.resource.Resource): The potentially + modified root structure. + + Example: + from twisted.web import static + my_page = static.File("web/mypage/") + my_page.indexNames = ["index.html"] + web_root.putChild("mypage", my_page) + + """ + return web_root + diff --git a/evennia/server/server.py b/evennia/server/server.py index 42f1529a6..531a7daf2 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -48,8 +48,9 @@ SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", 'server.restart') # module containing hook methods called during start_stop SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) -# module containing plugin services +# modules containing plugin services SERVER_SERVICES_PLUGIN_MODULES = [mod_import(module) for module in make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES)] +WEB_PLUGINS_MODULE = mod_import(settings.WEB_PLUGINS_MODULE) #------------------------------------------------------------ # Evennia Server settings @@ -511,6 +512,11 @@ if WEBSERVER_ENABLED: web_root.putChild("media", static.File(settings.MEDIA_ROOT)) # point our static resources to url /static web_root.putChild("static", static.File(settings.STATIC_ROOT)) + + if WEB_PLUGINS_MODULE: + # custom overloads + web_root = WEB_PLUGINS_MODULE.at_webserver_root_creation(web_root) + web_site = server.Site(web_root, logPath=settings.HTTP_LOG_FILE) for proxyport, serverport in WEBSERVER_PORTS: diff --git a/evennia/server/webserver.py b/evennia/server/webserver.py index e0b5bb2f2..ac19e0a0f 100644 --- a/evennia/server/webserver.py +++ b/evennia/server/webserver.py @@ -104,6 +104,7 @@ class EvenniaReverseProxyResource(ReverseProxyResource): # Website server resource # + class DjangoWebRoot(resource.Resource): """ This creates a web root (/) that Django diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 384c0fe70..4a43beacd 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -291,6 +291,8 @@ PORTAL_SERVICES_PLUGIN_MODULES = ["server.conf.portal_services_plugins"] # Module holding MSSP meta data. This is used by MUD-crawlers to determine # what type of game you are running, how many players you have etc. MSSP_META_MODULE = "server.conf.mssp" +# Module for web plugins. +WEB_PLUGINS_MODULE = "server.conf.web_plugins" # Tuple of modules implementing lock functions. All callable functions # inside these modules will be available as lock functions. LOCK_FUNC_MODULES = ("evennia.locks.lockfuncs", "server.conf.lockfuncs",)