Activation de CORS pour l'accès à l'API :
* accès total en mode développement * accès restreint à l'URL /api en mode production
This commit is contained in:
parent
ea2d3d0c43
commit
8847c351c1
@ -1,5 +1,6 @@
|
||||
Current version (0.2) :
|
||||
|
||||
- Activation des requêtes CORS pour permettre à une autre application d'accéder à l'API
|
||||
- MàJ vers Django 1.11.5
|
||||
- Activation d'une API (pour les consoles) accessible par l'administrateur (avec documentation)
|
||||
- Ajout d'une page d'accueil listant les jeux vidéos en cours, la liste complète et les 5 dernières activités sur ces derniers triées par date
|
||||
|
@ -6,3 +6,12 @@ REST_FRAMEWORK = {
|
||||
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
|
||||
'UNICODE_JSON': True,
|
||||
}
|
||||
|
||||
# CORS
|
||||
CORS_ORIGIN_ALLOW_ALL = False # disallow all website for cross site requests
|
||||
|
||||
# Authorized website for cross site requests
|
||||
CORS_ORIGIN_WHITELIST = (
|
||||
'localhost:8000',
|
||||
'127.0.0.1:8000'
|
||||
)
|
||||
|
@ -27,6 +27,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
'core',
|
||||
'games.apps.GamesConfig',
|
||||
]
|
||||
@ -35,6 +36,7 @@ MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
|
@ -7,5 +7,7 @@ SECRET_KEY = 'tqma23#v!#ecse_gz_u(1oa6+x%1uyi718an9%nefqhi$0q_eg'
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# CORS: allow all site to make cross site requests
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
|
@ -14,3 +14,6 @@ ALLOWED_HOSTS = [os.getenv('ALLOWED_HOSTS', '*')]
|
||||
# - if you use a proxy like Nginx, you need to add this line into config:
|
||||
# `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;`
|
||||
USE_X_FORWARDED_HOST = True
|
||||
|
||||
# CORS: as we only need to acces API, a regular expression is enough
|
||||
CORS_URLS_REGEX = r'^/api/.*$'
|
||||
|
@ -18,7 +18,7 @@ base_settings = [
|
||||
'components/common.py', # standard django settings
|
||||
'components/database.py', # SQLite 3
|
||||
'components/i18n.py', # Internationalisation and localization
|
||||
'components/api.py', # API (django rest framework)
|
||||
'components/api.py', # API (django rest framework) + CORS
|
||||
|
||||
# Select the right env:
|
||||
'environments/%s.py' % ENV,
|
||||
|
@ -4,3 +4,4 @@ PyYAML==3.12
|
||||
uWSGI==2.0.15
|
||||
djangorestframework==3.6.4
|
||||
coreapi==2.3.1
|
||||
django-cors-headers==2.1.0
|
||||
|
Loading…
Reference in New Issue
Block a user