58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
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
|
|
}
|