From 9cec04d058367967c62e02b01210a25d23e8bf6c Mon Sep 17 00:00:00 2001
From: James Graham <J.Graham@software.ac.uk>
Date: Tue, 26 Feb 2019 15:18:23 +0000
Subject: [PATCH] Add default server to Nginx config and extract ALLOWED_HOSTS
 from config

---
 deploy/nginx/sites-available/pedasi |  2 +-
 pedasi/settings.py                  | 19 +++++++------------
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/deploy/nginx/sites-available/pedasi b/deploy/nginx/sites-available/pedasi
index 59f59e4..fa28098 100644
--- a/deploy/nginx/sites-available/pedasi
+++ b/deploy/nginx/sites-available/pedasi
@@ -1,5 +1,5 @@
 server {
-    listen 80;
+    listen 80 default_server;
     server_name _;
 
     merge_slashes off;
diff --git a/pedasi/settings.py b/pedasi/settings.py
index 85512f8..0da9dee 100644
--- a/pedasi/settings.py
+++ b/pedasi/settings.py
@@ -26,6 +26,9 @@ DEBUG
   Run the server in debug mode?
   Default is 'false'.
 
+ALLOWED_HOSTS
+  List of hostnames on which the server is permitted to run
+
 DATABASE_URL
   URL to default SQL database - in `dj-database-url <https://github.com/kennethreitz/dj-database-url>`_ format.
   Default is SQLite3 'db.sqlite3' in project root directory.
@@ -41,7 +44,7 @@ import os
 
 from django.urls import reverse_lazy
 
-from decouple import config
+from decouple import config, Csv
 import dj_database_url
 import mongoengine
 
@@ -54,17 +57,9 @@ SECRET_KEY = config('SECRET_KEY')
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = config('DEBUG', default=False, cast=bool)
 
-if DEBUG:
-    ALLOWED_HOSTS = [
-        '*',
-    ]
-
-else:
-    ALLOWED_HOSTS = [
-        'localhost',
-        'pedasi-dev.eastus.cloudapp.azure.com',
-    ]
-
+ALLOWED_HOSTS = config('ALLOWED_HOSTS',
+                       cast=Csv(),
+                       default='*' if DEBUG else '127.0.0.1,localhost.localdomain,localhost')
 
 # Application definition
 
-- 
GitLab