Skip to content

Commit

Permalink
Improvements to dev ngrok settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Jun 21, 2024
1 parent 3b9b255 commit 0718b5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions conf/configs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
CSRF_COOKIE_SECURE = os.environ.get('MYPROJECT_CSRF_COOKIE_SECURE', 'True') == 'True'
SESSION_COOKIE_SECURE = os.environ.get('MYPROJECT_SESSION_COOKIE_SECURE', 'True') == 'True'
ALLOWED_HOSTS = os.environ.get('MYPROJECT_ALLOWED_HOSTS', '').split(' ')
CSRF_TRUSTED_ORIGINS = [PROJECT_HOST]

# Logging

Expand Down
10 changes: 10 additions & 0 deletions conf/configs/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
'127.0.0.1',
)

ALLOWED_HOSTS = common.ALLOWED_HOSTS + [
'.ngrok.io',
'.ngrok.app'
]

CSRF_TRUSTED_ORIGINS = common.CSRF_TRUSTED_ORIGINS + [
'https://*.ngrok.io',
'https://*.ngrok.app'
]

# Logging

LOGGING = {
Expand Down
5 changes: 3 additions & 2 deletions myproject/auth/services/authservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging

from django.apps import apps
from django.conf import settings
from django.contrib.auth import authenticate, login, logout, get_user_model
from django.urls import reverse
Expand All @@ -30,7 +31,7 @@ def process_register(request, user):
emailutils.send_multipart_email('email/register',
{
'PROJECT_NAME': settings.PROJECT_NAME,
'site_url': settings.PROJECT_HOST,
'site_url': apps.get_app_config('common').PROJECT_HOST,
'login_url': reverse('login'),
},
f'Welcome to {settings.PROJECT_NAME}', [user.email],
Expand Down Expand Up @@ -109,7 +110,7 @@ def process_forgot_password(request):
emailutils.send_multipart_email('email/forgot',
{
'password': password,
'site_url': settings.PROJECT_HOST,
'site_url': apps.get_app_config('common').PROJECT_HOST,
'settings_url': reverse('settings')
},
'Your Password Has Been Reset', [email])
Expand Down
4 changes: 3 additions & 1 deletion myproject/common/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CommonConfig(AppConfig):
name = 'myproject.common'
verbose_name = 'Common'

PROJECT_HOST = settings.PROJECT_HOST

def ready(self):
if settings.USE_NGROK and os.environ.get("NGROK_AUTHTOKEN"):
# pyngrok will only be installed, and should only ever be initialized, in a dev environment
Expand All @@ -28,7 +30,7 @@ def ready(self):
print(f"ngrok tunnel \"{public_url}\" -> \"http://127.0.0.1:{port}\"")

# Update any base URLs or webhooks to use the public ngrok URL
settings.PROJECT_HOST = public_url
self.PROJECT_HOST = public_url
CommonConfig.init_webhooks(public_url)

@staticmethod
Expand Down

0 comments on commit 0718b5c

Please sign in to comment.