Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from MaziniiX/main
Browse files Browse the repository at this point in the history
fix attempt
  • Loading branch information
MaziniiX authored Jun 22, 2024
2 parents 7ff320c + 85952d8 commit d6f0fc7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Django_Frontend/monprojet/monapp/templates/monapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
</div>
</div>
</nav>
{% if user.is_authenticated %}
<div>Logged in as: {{ user.username }}</div>
{% endif %}
<h1>Mon Application</h1>
</header>
<main>
Expand Down
20 changes: 11 additions & 9 deletions Django_Frontend/monprojet/monapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

# Create your views here.

def get_api_url(request: HttpRequest) -> str:
host = request.get_host()
protocol = 'https://'# if request.is_secure() else 'http://'
api_url = f'{protocol}api.{host}/api/common/'
return api_url


def client_create_view(request):
form = ClientForm(request.POST or None)
Expand Down Expand Up @@ -60,7 +56,7 @@ def register(request):
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
return redirect('login')
return redirect('Login')
else:
form = RegistrationForm()
return render(request, 'monapp/register.html', {'form': form})
Expand All @@ -74,19 +70,25 @@ def login(request):
user = authenticate(request, username=username, password=password)
if user is not None:
auth_login(request, user)
return redirect('home')
return redirect('Home')
else:
messages.error(request, 'Invalid username or password.')
else:
form = LoginForm()

return render(request, 'monapp/login.html', {'form': form})

def get_api_url(request: HttpRequest) -> str:
host = request.get_host()
protocol = 'https://'
api_url = f'{protocol}api.{host}/api/common/'
return api_url

def view_flights(request):
api_url = get_api_url(request) + 'flights/' # Adjusted to include the API endpoint
try:
response = requests.get(api_url)
response.raise_for_status() # This will raise an HTTPError if the response was an error
response = requests.get(api_url).json()
#response.raise_for_status() # This will raise an HTTPError if the response was an error
flights = response.json()
except requests.exceptions.HTTPError as http_err:
# Handle HTTP errors (e.g., endpoint not found, server error)
Expand Down
7 changes: 7 additions & 0 deletions Django_Frontend/monprojet/monprojet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
else:
ALLOWED_HOSTS = [os.getenv('DOMAIN')]

# Add near the top of the file
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Enforce HTTPS
SECURE_SSL_REDIRECT = True


# Application definition

INSTALLED_APPS = [
Expand Down
10 changes: 8 additions & 2 deletions Django_api/airline/airline/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
else:
ALLOWED_HOSTS = ["api" + os.getenv('DOMAIN')]

# Add near the top of the file
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Enforce HTTPS
SECURE_SSL_REDIRECT = True

# Application definition

Expand Down Expand Up @@ -69,7 +73,7 @@
]

if ENVIRONMENT != 'development':
CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN')]
CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN'), "http://" + os.getenv('DOMAIN'), "http://api." + os.getenv('DOMAIN')]
else:
CSRF_TRUSTED_ORIGINS = ['*']

Expand Down Expand Up @@ -165,5 +169,7 @@


CORS_ORIGIN_WHITELIST = [
"http://localhost:8010",
"https://api." + os.getenv('DOMAIN'),
"https://sae.local",
"http://sae.local",
]
4 changes: 2 additions & 2 deletions Docker-test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ services:
- "traefik.http.routers.django_frontend.entrypoints=websecure"
- "traefik.http.routers.django_frontend.tls=true"
- "traefik.http.routers.django_frontend_http.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.django_frontedn_http.entrypoints=web"
- "traefik.http.routers.django_frontedn_http.middlewares=redirect-to-https@file"
- "traefik.http.routers.django_frontend_http.entrypoints=web"
- "traefik.http.routers.django_frontend_http.middlewares=redirect-to-https@file"
- "traefik.http.services.django_frontend.loadbalancer.server.url=http://django_frontend:80"
hostname: django_frontend
depends_on:
Expand Down
4 changes: 4 additions & 0 deletions Docker-test/traefik/dynamic_conf.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
http:
middlewares:
add-xforwarded-proto-header:
headers:
customRequestHeaders:
X-Forwarded-Proto: "https"
redirect-to-https:
redirectScheme:
scheme: https
Expand Down

0 comments on commit d6f0fc7

Please sign in to comment.