From 6d192cf54d814bf1627195dd65b72d51ab111859 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 26 Oct 2020 14:39:47 -0500 Subject: [PATCH] Add SSL flexibility to chat server --- .gitignore | 2 ++ chat_box/views.py | 8 ++++++++ templates/chat/chat.html | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6880f54..849cda5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ resources/ranks.css resources/table.css sass_processed +node_modules/ +package-lock.json diff --git a/chat_box/views.py b/chat_box/views.py index 868436c..486051c 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -57,6 +57,14 @@ class ChatView(ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + + # hard code, should be fixed later + address = f'{self.request.get_host()}/ws/chat/' + if self.request.is_secure(): + context['ws_address'] = f'wss://{address}' + else: + context['ws_address'] = f'ws://{address}' + context['title'] = self.title last_five_minutes = timezone.now()-timezone.timedelta(minutes=5) context['online_users'] = Profile.objects \ diff --git a/templates/chat/chat.html b/templates/chat/chat.html index e3a4470..b839939 100644 --- a/templates/chat/chat.html +++ b/templates/chat/chat.html @@ -5,9 +5,8 @@ {% block js_media %}