Spaces:
Sleeping
Sleeping
| import uvicorn | |
| from fastapi import FastAPI, Depends, HTTPException, status | |
| from fastapi.security import HTTPBasic, HTTPBasicCredentials | |
| from fastapi.responses import FileResponse | |
| import os | |
| app = FastAPI() | |
| security = HTTPBasic() | |
| # ユーザー名とパスワードの設定 | |
| def authenticate(credentials: HTTPBasicCredentials = Depends(security)): | |
| correct_username = "admin" | |
| correct_password = "password123" | |
| if credentials.username != correct_username or credentials.password != correct_password: | |
| raise HTTPException( | |
| status_code=status.HTTP_401_UNAUTHORIZED, | |
| detail="Incorrect email or password", | |
| headers={"WWW-Authenticate": "Basic"}, | |
| ) | |
| return credentials.username | |
| # ルート (/) - index.html を表示 | |
| async def read_index(username: str = Depends(authenticate)): | |
| if os.path.exists('index.html'): | |
| return FileResponse('index.html') | |
| else: | |
| return "index.htmlが見つかりません。ファイルをアップロードしてください。" | |
| # 業務ポータル (/bussiness_portal) | |
| async def read_bussiness_portal(username: str = Depends(authenticate)): | |
| file_path = 'bussiness_portal.html' | |
| if os.path.exists(file_path): | |
| return FileResponse(file_path) | |
| else: | |
| return f"{file_path}が見つかりません。" | |
| # ------------------------------------------------------------------ | |
| # 【修正箇所】リンク切れ対策 | |
| # guide.htmlの戻るボタン (<a href="entry_info.html">) に合わせて | |
| # URLパスを "/entry_info.html" に変更しました。 | |
| # ------------------------------------------------------------------ | |
| async def read_entry_info(username: str = Depends(authenticate)): | |
| # ここで指定するファイル名は、実際にアップロードしたファイル名に合わせてください | |
| # 直近で作成したコードは entry_info.html として保存されている想定です | |
| file_path = 'entry_info.html' | |
| if os.path.exists(file_path): | |
| return FileResponse(file_path) | |
| else: | |
| # もしファイル名が entry_info04.html のままであれば、 | |
| # 上記の file_path = 'entry_info04.html' に書き換えてください | |
| return f"{file_path}が見つかりません。" | |
| # ガイドページ (/guide.html) | |
| async def read_guide(username: str = Depends(authenticate)): | |
| file_path = 'guide.html' | |
| if os.path.exists(file_path): | |
| return FileResponse(file_path) | |
| else: | |
| return f"{file_path}が見つかりません。" | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |