diff --git a/Caddyfile b/Caddyfile index ebcf6be..013bf0b 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,4 +1,4 @@ -http://guitarlions.localhost +http://my-demo.localhost root * /usr/src/app/ diff --git a/apps/back/consumers.py b/apps/back/consumers.py index 9b44383..71cd5cb 100644 --- a/apps/back/consumers.py +++ b/apps/back/consumers.py @@ -1,8 +1,7 @@ import json from channels.generic.websocket import AsyncWebsocketConsumer -from asgiref.sync import sync_to_async -class BackConsumer(AsyncWebsocketConsumer): +class BlogConsumer(AsyncWebsocketConsumer): def connect(self): ''' Cliente se conecta ''' @@ -12,15 +11,15 @@ class BackConsumer(AsyncWebsocketConsumer): self.room_group_name = "blog_%s" % self.room_name # Se une a la sala - await self.channel_layer.group_add(self.room_group_name, self.channel_name) + self.channel_layer.group_add(self.room_group_name, self.channel_name) # Informa al cliente del éxito - await self.accept() + self.accept() def disconnect(self, close_code): ''' Cliente se desconecta ''' # Leave room group - await self.channel_layer.group_discard(self.room_group_name, self.channel_name) + self.channel_layer.group_discard(self.room_group_name, self.channel_name) def receive(self, text_data): ''' Cliente envía información y nosotros la recibimos ''' @@ -29,7 +28,7 @@ class BackConsumer(AsyncWebsocketConsumer): text = text_data_json["text"] # Enviamos el mensaje a la sala - await self.channel_layer.group_send( + self.channel_layer.group_send( self.room_group_name, { "type": "chat_message", @@ -44,7 +43,7 @@ class BackConsumer(AsyncWebsocketConsumer): text = event["text"] # Send message to WebSocket - await self.send( + self.send( text_data=json.dumps( { "type": "chat_message", diff --git a/asgi.py b/asgi.py deleted file mode 100644 index 872bba4..0000000 --- a/asgi.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") -import django - -django.setup() - -from channels.routing import ProtocolTypeRouter - - -application = ProtocolTypeRouter({}) diff --git a/django-launcher.dev.sh b/django-launcher.dev.sh index d328d64..ef8946b 100644 --- a/django-launcher.dev.sh +++ b/django-launcher.dev.sh @@ -11,4 +11,4 @@ python3 manage.py migrate # Start server echo "Starting server" -uvicorn --host 0.0.0.0 --port 8000 --reload chapps.asgi:application +uvicorn --host 0.0.0.0 --port 8000 --reload my_demo.asgi:application diff --git a/django-launcher.pro.sh b/django-launcher.pro.sh index 2623dff..08b1576 100644 --- a/django-launcher.pro.sh +++ b/django-launcher.pro.sh @@ -11,4 +11,4 @@ python3 manage.py migrate # Start server echo "Starting server" -uvicorn --host 0.0.0.0 --port 8000 chapps.asgi:application +uvicorn --host 0.0.0.0 --port 8000 my_demo.asgi:application diff --git a/manage.py b/manage.py index 089ff59..f575c01 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mi_web.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_demo.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/mi_web/__init__.py b/my_demo/__init__.py similarity index 100% rename from mi_web/__init__.py rename to my_demo/__init__.py diff --git a/mi_web/asgi.py b/my_demo/asgi.py similarity index 72% rename from mi_web/asgi.py rename to my_demo/asgi.py index 4141348..cd414c9 100644 --- a/mi_web/asgi.py +++ b/my_demo/asgi.py @@ -1,6 +1,6 @@ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mi_web.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_demo.settings") import django django.setup() @@ -8,7 +8,7 @@ django.setup() from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application -from apps.chat.routing import websocket_urlpatterns +from apps.back.routing import websocket_urlpatterns application = ProtocolTypeRouter( diff --git a/mi_web/settings.py b/my_demo/settings.py similarity index 92% rename from mi_web/settings.py rename to my_demo/settings.py index aba53a8..3886d10 100644 --- a/mi_web/settings.py +++ b/my_demo/settings.py @@ -1,5 +1,5 @@ """ -Django settings for mi_web project. +Django settings for my_demo project. Generated by 'django-admin startproject' using Django 3.1.3. @@ -38,7 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'channels', - 'apps.chat', + 'apps.back', 'apps.front', ] @@ -52,7 +52,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'mi_web.urls' +ROOT_URLCONF = 'my_demo.urls' TEMPLATES = [ { @@ -77,8 +77,12 @@ TEMPLATES = [ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'mydatabase', + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'demo', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': '127.0.0.1', + 'PORT': '5432', } } diff --git a/mi_web/urls.py b/my_demo/urls.py similarity index 100% rename from mi_web/urls.py rename to my_demo/urls.py diff --git a/requirements.txt b/requirements.txt index e95b771..18dfc9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ # Django django -# Servidor para Django -daphne==2.4.1 -# Conector para PostgreSQL +# ASGI server +uvicorn +# Connect PostgreSQL psycopg2-binary # Channels channels==2.4.0 -# Conector de Redis para Channels +# Connect Redis for Channels channels_redis \ No newline at end of file