-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from lvalics/main
Some fixes
- Loading branch information
Showing
7 changed files
with
121 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
from django.utils.deprecation import MiddlewareMixin | ||
from web.models.chatbot import Chatbot | ||
import os | ||
|
||
class CorsMiddleware(MiddlewareMixin): | ||
def process_response(self, request, response): | ||
# Get the origin of the request | ||
origin = request.META.get('HTTP_ORIGIN') | ||
|
||
# Check if the origin is in the database | ||
origin_in_db = Chatbot.objects.filter(website=origin).exists() | ||
# print(f"Origin of the request: {origin}") | ||
# print(f"Is the origin in the database: {origin_in_db}") | ||
# Get APP_URL from environment variables | ||
app_url = os.getenv('APP_URL') | ||
#print(f"Origin of the APP_URL: {app_url} == {origin}") | ||
|
||
if origin_in_db: | ||
# Check if the origin is in the database or equal to APP_URL | ||
origin_in_db = origin == app_url or Chatbot.objects.filter(website=origin).exists() | ||
|
||
if origin_in_db: | ||
# Add the 'Access-Control-Allow-Origin' header to the response | ||
response['Access-Control-Allow-Origin'] = origin | ||
response['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS' | ||
response['Access-Control-Allow-Headers'] = 'X-Requested-With, Content-Type, X-Bot-Token' | ||
|
||
# print(f"Website URLs checked: {[chatbot.website for chatbot in Chatbot.objects.all()]}") | ||
#print(f"Website URLs checked: {[chatbot.website for chatbot in Chatbot.objects.all()]}") | ||
# print(f"Response status code: {response.status_code}") | ||
# print(f"Response content: {response.content}") | ||
# print(f"Response headers: {response.headers}") | ||
|
||
|
||
#print(f"Response headers: {response.headers}") | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
dj_backend_server/web/migrations/0006_crawledpages_content_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.3 on 2023-10-27 17:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('web', '0005_pdfdatasourceerrorlog'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='crawledpages', | ||
name='content_file', | ||
field=models.CharField(max_length=255, null=True), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
dj_backend_server/web/migrations/0007_alter_crawledpages_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.3 on 2023-10-27 17:49 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('web', '0006_crawledpages_content_file'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='crawledpages', | ||
name='id', | ||
field=models.AutoField(primary_key=True, serialize=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters