Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ViaResto-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aymeric Chaumont
ViaResto-website
Merge requests
!53
Interface admin
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Interface admin
interface_admin
into
main
Overview
0
Commits
10
Pipelines
10
Changes
1
Merged
Antoine Gaudron-Desjardins
requested to merge
interface_admin
into
main
2 years ago
Overview
0
Commits
10
Pipelines
10
Changes
1
0
0
Merge request reports
Viewing commit
05fc5ab6
Prev
Next
Show latest version
1 file
+
1
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
05fc5ab6
fix path
· 05fc5ab6
Antoine Gaudron-Desjardins
authored
2 years ago
backend/main.py
+
23
−
3
View file @ 05fc5ab6
Edit in single-file editor
Open in Web IDE
Show full file
from
fastapi
import
FastAPI
from
fastapi
import
Cookie
,
Depends
,
FastAPI
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
JSONResponse
from
fastapi.openapi.docs
import
get_swagger_ui_html
from
fastapi.openapi.utils
import
get_openapi
from
sqlalchemy.orm
import
Session
from
dotenv
import
load_dotenv
from
threading
import
Thread
from
asyncio
import
run
import
os
from
db
import
database
,
models
from
db
import
database
,
models
,
crud
from
db.database
import
get_db
from
routers
import
*
from
video_capture
import
handle_cameras
app
=
FastAPI
(
docs_url
=
"
/api/docs
"
,
openapi_url
=
"
/api/openapi.js
on
"
)
app
=
FastAPI
(
docs_url
=
None
,
redoc_url
=
None
,
openapi_url
=
N
on
e
)
# load environment variables
load_dotenv
()
@@ -35,6 +40,21 @@ async def on_startup():
t
.
start
()
# Docs OpenAPI
@app.get
(
"
/api/openapi.json
"
)
async
def
get_open_api_endpoint
(
connect_id
:
str
=
Cookie
(...),
db
:
Session
=
Depends
(
get_db
)):
user
=
crud
.
get_user
(
connect_id
,
db
)
if
user
.
admin
:
return
JSONResponse
(
get_openapi
(
title
=
"
FastAPI
"
,
version
=
1
,
routes
=
app
.
routes
))
@app.get
(
"
/api/docs
"
)
async
def
get_documentation
(
connect_id
:
str
=
Cookie
(...),
db
:
Session
=
Depends
(
get_db
)):
user
=
crud
.
get_user
(
connect_id
,
db
)
if
user
.
admin
:
return
get_swagger_ui_html
(
openapi_url
=
"
/api/openapi.json
"
,
title
=
"
docs
"
)
# Integration of routers
app
.
include_router
(
infos
.
router
)
app
.
include_router
(
records
.
router
)
Loading