Skip to content

Commit

Permalink
Merge pull request EGCETSII#42 from Full-Tortuga/fix/EGCETSII#25-cors…
Browse files Browse the repository at this point in the history
…-settings

EGCETSII#25-fix: cors headers for react dev env
  • Loading branch information
pedalopon authored Dec 26, 2021
2 parents 7636790 + 798af84 commit 6dd4395
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
19 changes: 6 additions & 13 deletions decide/administration/frontend/src/api/axios.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import Axios, { AxiosRequestConfig } from "axios";
import Axios from "axios";

import { sessionUtils } from "utils";

const API_URL = "http://localhost:8000/administration/api";

export const axios = Axios.create({
baseURL: API_URL,
});

// Headers interceptor
axios.interceptors.request.use((config: AxiosRequestConfig) => {
if (config.headers) {
// content-type
config.headers.Accept = "application/json";
config.headers.ContentType = "application/json";
config.headers["Access-Control-Allow-Origin"] = "*";
}

return config;
withCredentials: true,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});

// Auth interceptor (logout)
Expand Down
11 changes: 1 addition & 10 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOW_CREDENTIALS = True

CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'http://localhost:3000/#',
'http://localhost:8000/#',
)
CORS_ALLOW_HEADERS = ['*']
# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -63,6 +54,7 @@
'base.backends.AuthBackend',
]


MODULES = [
'administration',
'authentication',
Expand Down Expand Up @@ -194,4 +186,3 @@
vars()[k] = v

INSTALLED_APPS = INSTALLED_APPS + MODULES
# added to solve CORS
21 changes: 10 additions & 11 deletions decide/local_settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# dev env CORS SETTINGS
BASEURL = 'http://localhost:8000'
FE_BASEURL = 'http://localhost:3000'

ALLOWED_HOSTS = ['*']

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'http://localhost:3000',
BASEURL, FE_BASEURL
)
CSRF_TRUSTED_ORIGINS = [
BASEURL, FE_BASEURL
]


# Modules in use, commented modules that you won't use
MODULES = [
Expand All @@ -20,7 +28,6 @@
'voting',
]

BASEURL = 'http://localhost:8000'

APIS = {
'administration': BASEURL,
Expand All @@ -42,14 +49,6 @@
'CLIENT': {
'host': '127.0.0.1',
}
},
'postgres': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'decide',
'PASSWORD': 'decide',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ django-utils==0.0.2
Django==2.2.5
pycryptodome==3.6.6
djangorestframework==3.7.7
django-cors-headers==2.1.0
django-cors-headers==3.0.1
requests==2.23.0
django-filter==21.1
psycopg2-binary==2.8.6
Expand Down

0 comments on commit 6dd4395

Please sign in to comment.