From 6e57862d2602c635761ea8eb51d16a01ed22c21d Mon Sep 17 00:00:00 2001 From: wangsiyuan <2392948297@qq.com> Date: Tue, 23 Jan 2024 16:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=20website.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 website.py diff --git a/website.py b/website.py new file mode 100644 index 0000000..29e0c0f --- /dev/null +++ b/website.py @@ -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 + }