mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-07 20:46:45 +00:00
📦 add nonebot plugin docs
This commit is contained in:
37
packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
Normal file
37
packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Author : yanyongyu
|
||||
@Date : 2020-11-22 00:56:58
|
||||
@LastEditors : yanyongyu
|
||||
@LastEditTime : 2020-11-22 01:00:29
|
||||
@Description : None
|
||||
@GitHub : https://github.com/yanyongyu
|
||||
"""
|
||||
__author__ = "yanyongyu"
|
||||
|
||||
import importlib
|
||||
|
||||
import nonebot
|
||||
from nonebot.log import logger
|
||||
|
||||
|
||||
def init():
|
||||
driver = nonebot.get_driver()
|
||||
try:
|
||||
_module = importlib.import_module(
|
||||
f"nonebot_plugin_docs.drivers.{driver.type}")
|
||||
except ImportError:
|
||||
logger.warning(f"Driver {driver.type} not supported")
|
||||
return
|
||||
register_route = getattr(_module, "register_route")
|
||||
register_route(driver)
|
||||
host = str(driver.config.host)
|
||||
port = driver.config.port
|
||||
if host in ["0.0.0.0", "127.0.0.1"]:
|
||||
host = "localhost"
|
||||
logger.opt(colors=True).info(f"Nonebot docs will be running at: "
|
||||
f"<b><u>http://{host}:{port}/docs/</u></b>")
|
||||
|
||||
|
||||
init()
|
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Author : yanyongyu
|
||||
@Date : 2020-11-22 00:56:31
|
||||
@LastEditors : yanyongyu
|
||||
@LastEditTime : 2020-11-22 01:03:05
|
||||
@Description : None
|
||||
@GitHub : https://github.com/yanyongyu
|
||||
"""
|
||||
__author__ = "yanyongyu"
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot.drivers.fastapi import Driver
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
|
||||
def register_route(driver: Driver, socketio):
|
||||
app = driver.server_app
|
||||
|
||||
static_path = str((Path(__file__).parent / ".." / "dist").resolve())
|
||||
|
||||
app.mount("/docs",
|
||||
StaticFiles(directory=static_path, html=True),
|
||||
name="docs")
|
Reference in New Issue
Block a user