Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
e231333b
"...io/git@developer.sourcefind.cn:yaoyuping/nndetection.git" did not exist on "9aaa3f43949fca0e7b699cdbbc63b8e2f9afef45"
Commit
e231333b
authored
May 28, 2024
by
Timothy J. Baek
Browse files
refac
parent
b870fd11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
13 deletions
+25
-13
backend/main.py
backend/main.py
+25
-13
No files found.
backend/main.py
View file @
e231333b
...
...
@@ -12,6 +12,7 @@ import mimetypes
from
fastapi
import
FastAPI
,
Request
,
Depends
,
status
from
fastapi.staticfiles
import
StaticFiles
from
fastapi.responses
import
JSONResponse
from
fastapi
import
HTTPException
from
fastapi.middleware.wsgi
import
WSGIMiddleware
from
fastapi.middleware.cors
import
CORSMiddleware
...
...
@@ -123,15 +124,6 @@ app.state.MODELS = {}
origins
=
[
"*"
]
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
allow_credentials
=
True
,
allow_methods
=
[
"*"
],
allow_headers
=
[
"*"
],
)
# Custom middleware to add security headers
# class SecurityHeadersMiddleware(BaseHTTPMiddleware):
# async def dispatch(self, request: Request, call_next):
...
...
@@ -276,10 +268,8 @@ class PipelineMiddleware(BaseHTTPMiddleware):
except
:
pass
print
(
sorted_filters
)
for
filter
in
sorted_filters
:
r
=
None
try
:
urlIdx
=
filter
[
"urlIdx"
]
...
...
@@ -303,7 +293,20 @@ class PipelineMiddleware(BaseHTTPMiddleware):
except
Exception
as
e
:
# Handle connection error here
print
(
f
"Connection error:
{
e
}
"
)
pass
if
r
is
not
None
:
try
:
res
=
r
.
json
()
if
"detail"
in
res
:
return
JSONResponse
(
status_code
=
r
.
status_code
,
content
=
res
,
)
except
:
pass
else
:
pass
modified_body_bytes
=
json
.
dumps
(
data
).
encode
(
"utf-8"
)
# Replace the request body with the modified one
...
...
@@ -328,6 +331,15 @@ class PipelineMiddleware(BaseHTTPMiddleware):
app
.
add_middleware
(
PipelineMiddleware
)
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
allow_credentials
=
True
,
allow_methods
=
[
"*"
],
allow_headers
=
[
"*"
],
)
@
app
.
middleware
(
"http"
)
async
def
check_url
(
request
:
Request
,
call_next
):
if
len
(
app
.
state
.
MODELS
)
==
0
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment