Bearle / django_private_chat2

Chat app for Django, powered by Django Channels, Websockets & Asyncio
MIT License
295 stars 80 forks source link

Cross Origin requests to 127.0.0.1:8000 not allowed when running the example code #16

Closed merc1er closed 3 years ago

merc1er commented 3 years ago

Description

Running the test app results in a cross origin error

What I Did

python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

In the logs:

(0.001) SELECT "django_session"."session_key", "django_session"."session_data", "django_session"."expire_date" FROM "django_session" WHERE ("django_session"."expire_date" > '2021-06-21 11:44:57.252571' AND "django_session"."session_key" = 'XXX') LIMIT 21; args=('2021-06-21 11:44:57.252571', 'XXX')
(0.000) SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = 1 LIMIT 21; args=(1,)
WebSocket CONNECT /chat_ws [127.0.0.1:51810]
(0.001) SELECT "django_private_chat2_dialogsmodel"."user1_id", "django_private_chat2_dialogsmodel"."user2_id" FROM "django_private_chat2_dialogsmodel" WHERE ("django_private_chat2_dialogsmodel"."user1_id" = 1 OR "django_private_chat2_dialogsmodel"."user2_id" = 1); args=(1, 1)

In the frontend: Screenshot 2021-06-21 at 18 39 37

delneg commented 3 years ago

Hello,

That can happen if you use localhost:8000 instead of 127.0.0.1:8000 Please use 127.0.0.1:8000 for local testing (or change the url as described in #7 )

merc1er commented 3 years ago

That worked! Thank you 🙏🏻