Skip to content

Commit

Permalink
Merge pull request #39 from gip-inclusion/madjid-asa/add-well-known-f…
Browse files Browse the repository at this point in the history
…older

feat: Ajout d'une vue pour afficher les fichiers .well_known
  • Loading branch information
madjid-asa authored Jul 10, 2024
2 parents eff1eb9 + d63de53 commit 82bc0a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path
Expand All @@ -21,4 +22,5 @@
urlpatterns = [
path("", include("services.urls")),
path("", include("cms.urls")),
path(".well-known/", include("well_known.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
11 changes: 11 additions & 0 deletions well_known/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import include, path


from .views import serve_text_file


urlpatterns = [
path("pdi-pgp.asc", serve_text_file, {"file_name": "pdi-pgp.asc"}, name="pdi-pgp"),
path("security-policy.txt", serve_text_file, {"file_name": "security-policy.txt"}, name="security-policy"),
path("security.txt", serve_text_file, {"file_name": "security.txt"}, name="security"),
]
12 changes: 12 additions & 0 deletions well_known/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from django.http import HttpResponse


def serve_text_file(request, file_name):
file_path = os.path.join('static', '.well-known', file_name)
try:
with open(file_path, 'r') as file:
content = file.read()
return HttpResponse(content, content_type='text/plain')
except FileNotFoundError:
return HttpResponse("File not found.", status=404)

0 comments on commit 82bc0a4

Please sign in to comment.