Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

追加: GET / API にポータルページを配置 #1169

Merged
merged 8 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates

from voicevox_engine import __version__
Expand Down Expand Up @@ -176,6 +177,25 @@ def get_core(core_version: Optional[str]) -> CoreAdapter:
)
)

@app.get("/", response_class=HTMLResponse, tags=["その他"])
async def get_portal() -> str:
"""ポータルページを返します。"""
engine_name = engine_manifest_data.name

return f"""
<html>
<head>
<title>{engine_name}</title>
</head>
<body>
<h1>{engine_name}</h1>
{engine_name} へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント & API 呼び出し</a></li>
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
</ul></body></html>
"""

app = configure_openapi_schema(app)

return app
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions test/e2e/single_api/__snapshots__/test_get_root.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# serializer version: 1
# name: test_get_root_200
'''

<html>
<head>
<title>DUMMY Engine</title>
</head>
<body>
<h1>DUMMY Engine</h1>
DUMMY Engine へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント & API 呼び出し</a></li>
</ul></body></html>

'''
# ---
12 changes: 12 additions & 0 deletions test/e2e/single_api/test_get_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
/ API のテスト
"""

from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


def test_get_root_200(client: TestClient, snapshot: SnapshotAssertion) -> None:
response = client.get("/")
assert response.status_code == 200
assert snapshot == response.content.decode("utf-8")