Skip to content

Commit

Permalink
Angel/fix cors error swagger (#32)
Browse files Browse the repository at this point in the history
* Feat: write a return message

* fix: upgradeCORS params for swagger
  • Loading branch information
Angel-Dijoux authored Jan 16, 2024
1 parent 5448e6c commit c6b128e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/config/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ def get_swagger_api_spec(
swagger_config = {
"host": ["localhost:5005" if is_dev() else "api.nc-elki.v6.army"],
"schemes": ["http" if is_dev() else "https"],
"headers": [
("Access-Control-Allow-Origin", "*"),
("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"),
("Access-Control-Allow-Credentials", "true"),
],
"headers": [],
"specs": [
{
"endpoint": "apispec",
Expand Down
10 changes: 10 additions & 0 deletions src/middlewares.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import Response

from src.constants.env import is_dev


def add_security_headers(response: Response) -> Response:
response.headers.add("X-Content-Type-Options", "nosniff")
Expand All @@ -10,6 +12,14 @@ def add_security_headers(response: Response) -> Response:
response.headers.add(
"Access-Control-Allow-Methods", ",".join(["GET", "POST", "DELETE"])
)
response.headers.add(
"Access-Control-Allow-Origin",
"".join(
["http://127.0.0.1:5005" if is_dev() else "https://api.nc-elki.v6.army"]
),
)
response.headers.add("Access-Control-Allow-Headers", "Authorization, Content-Type")
response.headers.add("Access-Control-Max-Age", "1728000")
response.headers.add("X-XSS-Protection", "1; mode=block")
response.headers.set("Server", "Jojo's")

Expand Down

0 comments on commit c6b128e

Please sign in to comment.