Skip to content
Snippets Groups Projects
Commit aea0e722 authored by abrinna's avatar abrinna Committed by Quentin Ulmer
Browse files

Tested Frontend/Backend Interaction. Created CORS Settings and made test sparql view csrf excempt

parent 0103bfef
Branches
No related tags found
1 merge request!4Merge newest version into main
...@@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-)7a93cype161or54hynz3y%+&i2&ba8g_&chlz&toncfy2783f ...@@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-)7a93cype161or54hynz3y%+&i2&ba8g_&chlz&toncfy2783f
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ["*"]
# Application definition # Application definition
...@@ -34,6 +34,7 @@ ALLOWED_HOSTS = [] ...@@ -34,6 +34,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [ INSTALLED_APPS = [
'artguide_api.apps.ArtguideApiConfig', 'artguide_api.apps.ArtguideApiConfig',
'django.contrib.admin', 'django.contrib.admin',
'corsheaders',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
...@@ -44,6 +45,7 @@ INSTALLED_APPS = [ ...@@ -44,6 +45,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
...@@ -125,3 +127,6 @@ STATIC_URL = '/static/' ...@@ -125,3 +127,6 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CORS_ORIGIN_ALLOW_ALL = True
CSRF_TRUSTED_ORIGINS = ["*"]
...@@ -4,7 +4,10 @@ from django.http import JsonResponse ...@@ -4,7 +4,10 @@ from django.http import JsonResponse
from SPARQLWrapper import SPARQLWrapper, JSON from SPARQLWrapper import SPARQLWrapper, JSON
import os import os
import json import json
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def sparql_query(request): def sparql_query(request):
""" """
This function executes a SPARQL query received from the frontend and returns the results in JSON format. This function executes a SPARQL query received from the frontend and returns the results in JSON format.
......
...@@ -16,6 +16,7 @@ export class BackendApiService { ...@@ -16,6 +16,7 @@ export class BackendApiService {
const url = `${this.apiUrl}/sparql?query=${query}`; const url = `${this.apiUrl}/sparql?query=${query}`;
console.log('sending request to: ', url) console.log('sending request to: ', url)
const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
headers.set('Access-Control-Allow-Origin', '*')
const body = { query: query }; const body = { query: query };
return this.http.post<any>(this.apiUrl, body, { headers: headers }); return this.http.post<any>(this.apiUrl, body, { headers: headers });
......
export const environment = { export const environment = {
production: false, production: false,
apiUrl: 'http://localhost:8000' // Beispiel-URL für die Entwicklung apiUrl: 'http://localhost:8000/sparql/' // Beispiel-URL für die Entwicklung
}; };
Django>=3.0,<4.0 Django>=3.0,<4.0
sparqlwrapper>=2.0.0 sparqlwrapper>=2.0.0
django-cors-headers>=4.0.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment