-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
46 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import logging | ||
from asyncio import run as asyncio_run | ||
|
||
from litestar import Litestar | ||
from litestar.openapi import OpenAPIConfig, OpenAPIController | ||
from litestar.openapi.spec import Server | ||
from sshared.api.uvicorn import get_uvicorn_params_from_config | ||
from sspeedup.api.litestar import EXCEPTION_HANDLERS | ||
from uvicorn import run as uvicorn_run | ||
|
||
from api import API_ROUTER | ||
from models import init_db | ||
from utils.config import CONFIG | ||
from utils.log import logger | ||
|
@@ -11,17 +17,39 @@ | |
logging.getLogger("httpcore").setLevel(logging.CRITICAL) | ||
|
||
|
||
class CustomOpenAPIController(OpenAPIController): | ||
path = "/docs" | ||
swagger_ui_version = "5.17.14" | ||
swagger_css_url = ( | ||
"https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css" | ||
) | ||
swagger_ui_bundle_js_url = ( | ||
"https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js" | ||
) | ||
swagger_ui_standalone_preset_js_url = "https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-standalone-preset.js" | ||
favicon_url = "https://tools.sscreator.com/favicon-vector.svg" | ||
|
||
|
||
app = Litestar( | ||
route_handlers=[API_ROUTER], | ||
exception_handlers=EXCEPTION_HANDLERS, | ||
openapi_config=OpenAPIConfig( | ||
openapi_controller=CustomOpenAPIController, | ||
title="JTools API", | ||
version="v1.0.0", | ||
servers=[Server(description="主端点", url="/api")], | ||
use_handler_docstrings=True, | ||
root_schema_site="swagger", | ||
enabled_endpoints={"swagger", "openapi.json"}, | ||
), | ||
) | ||
|
||
if __name__ == "__main__": | ||
asyncio_run(init_db()) | ||
logger.debug("初始化数据库成功") | ||
|
||
logger.info("启动 API 服务") | ||
uvicorn_run( | ||
app="app:app", | ||
host=CONFIG.uvicorn.host, | ||
port=CONFIG.uvicorn.port, | ||
log_level=CONFIG.uvicorn.log_level, | ||
workers=CONFIG.uvicorn.workers, | ||
reload=CONFIG.uvicorn.reload, | ||
access_log=CONFIG.uvicorn.access_log, | ||
app="main:app", | ||
**get_uvicorn_params_from_config(CONFIG.uvicorn), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.