Initial commit
This commit is contained in:
3
plugin/cors/__init__.py
Normal file
3
plugin/cors/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .cors import CorsPlugin as CORSMiddleware
|
||||
|
||||
__all__ = ["CORSMiddleware"]
|
||||
23
plugin/cors/cors.py
Normal file
23
plugin/cors/cors.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
from plugin.base import Plugin
|
||||
|
||||
|
||||
class CorsPlugin(Plugin):
|
||||
def __init__(self, app: FastAPI):
|
||||
self.name = "CorsPlugin"
|
||||
self.description = "Enable Cross-Origin Resource Sharing (CORS)"
|
||||
self.version = "1.0.0"
|
||||
self.app = app
|
||||
|
||||
def install(self):
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
# 添加CORS中间件解决跨域问题
|
||||
self.app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
Reference in New Issue
Block a user