Skip to content

Commit 27416ae

Browse files
authored
Merge pull request #110 from pgulb/109-disable-openapi-and-swagger-when-deploying
109 disable openapi and swagger when deploying
2 parents 2ce2f32 + 585dea7 commit 27416ae

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

.github/workflows/deploy-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
run: |
4141
echo ${{ secrets.FROG_KEY }} | base64 -d > frog &&
4242
chmod 600 frog &&
43-
ssh -o StrictHostKeyChecking=no -i frog ${{ secrets.FROG_ADDRESS }} -p${{ secrets.FROG_PORT }} "docker run -d -p 30149:6789 -e MONGO_URL='${{ secrets.MONGO_URL }}' --name flush-log-api --restart=unless-stopped ghcr.io/pgulb/flush-log:api"
43+
ssh -o StrictHostKeyChecking=no -i frog ${{ secrets.FROG_ADDRESS }} -p${{ secrets.FROG_PORT }} "docker run -d -p 30149:6789 -e DISABLE_OPENAPI='true' -e MONGO_URL='${{ secrets.MONGO_URL }}' --name flush-log-api --restart=unless-stopped ghcr.io/pgulb/flush-log:api"

api/main.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,21 @@
2424
from httpbasic import HTTPBasic
2525
from models import Feedback, Flush, User
2626

27-
app = fastapi.FastAPI()
27+
logger = logging.getLogger(__name__)
28+
logging.getLogger("passlib").setLevel(logging.ERROR)
29+
30+
app_args = {}
31+
disable_openapi = os.getenv("DISABLE_OPENAPI")
32+
try:
33+
if disable_openapi.lower() == "true":
34+
app_args["docs_url"] = None
35+
app_args["redoc_url"] = None
36+
app_args["openapi_url"] = None
37+
logger.info("OpenAPI and Swagger is DISABLED")
38+
except AttributeError:
39+
pass
40+
app = fastapi.FastAPI(**app_args)
41+
2842
origins = [
2943
"*",
3044
]
@@ -37,9 +51,6 @@
3751
)
3852
security = HTTPBasic()
3953

40-
logger = logging.getLogger(__name__)
41-
logging.getLogger("passlib").setLevel(logging.ERROR)
42-
4354
mongo_setting = os.getenv("MONGO_URL")
4455
if mongo_setting is None:
4556
raise ValueError("MONGO_URL not set")

0 commit comments

Comments
 (0)