File size: 2,717 Bytes
018061e
 
 
 
9c78ee0
018061e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c78ee0
018061e
 
9c78ee0
 
 
 
 
6e1492d
9c78ee0
 
 
 
 
 
 
 
6e1492d
 
 
 
 
f1b5c4f
b4156bb
6e1492d
 
f1b5c4f
6e1492d
b4156bb
 
 
6e1492d
 
b4156bb
 
6e1492d
368c336
 
380437b
9c78ee0
 
 
 
018061e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 を表示
@app.get("/")
async def read_index(username: str = Depends(authenticate)):
    if os.path.exists('index.html'):
        return FileResponse('index.html')
    else:
        return "index.htmlが見つかりません。ファイルをアップロードしてください。"

# 業務ポータル (/bussiness_portal)
@app.get("/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" に変更しました。
# ------------------------------------------------------------------
@app.get("/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)
@app.get("/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)