Compare commits

..

4 Commits

Author SHA1 Message Date
wangsiyuan ee0762b0b1 创建 website.cpython-311.pyc 2024-01-23 16:01:27 +08:00
wangsiyuan 13d2081aff 更新 main.py 2024-01-23 16:01:25 +08:00
wangsiyuan 6e57862d26 创建 website.py 2024-01-23 16:01:22 +08:00
wangsiyuan 319b4d2c79 更新 .gitignore 2024-01-23 16:01:16 +08:00
4 changed files with 58 additions and 1 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
__pycache__ __pycache__
venv venv
__pycache__/main.cpython-311.pyc __pycache__/main.cpython-311.pyc
pictures/

Binary file not shown.

View File

@ -1,6 +1,5 @@
from fastapi import FastAPI, HTTPException, Request from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
import base64
import os import os
app = FastAPI() app = FastAPI()

57
website.py Normal file
View File

@ -0,0 +1,57 @@
from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
import os
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"], # 允许的源列表
allow_credentials=True,
allow_methods=["*"], # 允许的方法
allow_headers=["*"], # 允许的头
)
@app.get("/")
async def root():
return "welcome to fastAPI!"
@app.get("/api/get-menu")
async def get_menu():
menu_list = [
{"id": 1, "menu_name": "首页", "url": "/", "src": "/index.svg"},
{"id": 2, "menu_name": "图片", "url": "/photos", "src": "/photo.svg"},
{"id": 3, "menu_name": "视频", "url": "/videos", "src": "/videos.svg"},
{"id": 4, "menu_name": "关于", "url": "/about", "src": "/about.svg"}
]
return {
"code": 0,
"msg": "ok",
"data": menu_list
}
@app.get("/api/get-photo-list")
async def get_photo_list():
photo_list = [
{"id": 1, "photo_name": "1", "photo_size": "1", "url": "/index.svg"},
{"id": 2, "photo_name": "2", "photo_size": "1", "url": "/photo.svg"},
{"id": 3, "photo_name": "3", "photo_size": "1", "url": "/videos.svg"},
{"id": 4, "photo_name": "4", "photo_size": "1", "url": "/about.svg"},
{"id": 5, "photo_name": "5", "photo_size": "1", "url": "/index.svg"},
{"id": 6, "photo_name": "6", "photo_size": "1", "url": "/photo.svg"},
{"id": 7, "photo_name": "7", "photo_size": "1", "url": "/videos.svg"},
{"id": 8, "photo_name": "8", "photo_size": "1", "url": "/about.svg"},
{"id": 9, "photo_name": "9", "photo_size": "1", "url": "/index.svg"},
{"id": 10, "photo_name": "10", "photo_size": "1", "url": "/photo.svg"},
{"id": 11, "photo_name": "11", "photo_size": "1", "url": "/videos.svg"},
{"id": 12, "photo_name": "12", "photo_size": "1", "url": "/about.svg"}
]
return {
"code": 0,
"msg": "ok",
"data": photo_list
}