💁🏻完善js和css文件在自部署的路由
This commit is contained in:
		
							
								
								
									
										12
									
								
								server.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								server.py
									
									
									
									
									
								
							@@ -12,6 +12,7 @@ app = FastAPI()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# 设置静态文件目录
 | 
					# 设置静态文件目录
 | 
				
			||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
 | 
					app.mount("/static", StaticFiles(directory="static"), name="static")
 | 
				
			||||||
 | 
					app.mount("/main", StaticFiles(directory="main"), name="main")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 添加 CORS 中间件
 | 
					# 添加 CORS 中间件
 | 
				
			||||||
app.add_middleware(
 | 
					app.add_middleware(
 | 
				
			||||||
@@ -36,6 +37,17 @@ async def bg_light():
 | 
				
			|||||||
async def bg_dark():
 | 
					async def bg_dark():
 | 
				
			||||||
    return FileResponse('static/bg-dark.webp')
 | 
					    return FileResponse('static/bg-dark.webp')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 返回资源文件
 | 
				
			||||||
 | 
					# 返回 CSS 文件
 | 
				
			||||||
 | 
					@app.get("/fclite.css", response_class=HTMLResponse)
 | 
				
			||||||
 | 
					async def get_fclite_css():
 | 
				
			||||||
 | 
					    return FileResponse('./main/fclite.css')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 返回 JS 文件
 | 
				
			||||||
 | 
					@app.get("/fclite.js", response_class=HTMLResponse)
 | 
				
			||||||
 | 
					async def get_fclite_js():
 | 
				
			||||||
 | 
					    return FileResponse('./main/fclite.js')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.get("/", response_class=HTMLResponse)
 | 
					@app.get("/", response_class=HTMLResponse)
 | 
				
			||||||
async def root():
 | 
					async def root():
 | 
				
			||||||
    return FileResponse('./static/index.html')
 | 
					    return FileResponse('./static/index.html')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user