Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework the hosts def #308

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MSSQL_DB_HOST=127.0.0.1

DB_NAME=test_imis
DB_TEST_NAME=test_imis

# Site root that will prefix all exposed endpoints. It's required when working with openIMIS frontend
SITE_ROOT=api
# Should the debug be on (i.e. debug information will be displayed)
Expand Down
10 changes: 9 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@
"django": true,
"cwd": "${workspaceRoot}/openIMIS",
"env": {
"DB_DEFAULT": "${input:dbEngine}"
"DB_DEFAULT": "${input:dbEngine}",
"PROTOS": "http",
"HOSTS": "localhost",
},
"justMyCode": false
},
Expand All @@ -240,6 +242,8 @@
"cwd": "${workspaceRoot}/openIMIS",
"env": {
"DB_DEFAULT": "${input:dbEngine}",
"PROTOS": "http",
"HOSTS": "localhost",
//"ASYNC": "PROD",
"CELERY_BROKER_URL": "memory://openIMIS-test//",
"CELERY_RESULT_BACKEND": "cache+memory://openIMIS-test//"
Expand All @@ -261,6 +265,8 @@
"cwd": "${workspaceRoot}/openIMIS",
"env": {
"DB_DEFAULT": "${input:dbEngine}",
"PROTOS": "http",
"HOSTS": "localhost",
//"ASYNC": "PROD",
"CELERY_BROKER_URL": "memory://openIMIS-test//",
"CELERY_RESULT_BACKEND": "cache+memory://openIMIS-test//"
Expand All @@ -279,6 +285,8 @@
"args": ["-A", "openIMIS", "worker", "-l", "debug", "-Q", "queueName"],
"env": {
"DB_DEFAULT": "${input:dbEngine}",
"PROTOS": "http",
"HOSTS": "localhost",
"ASYNC": "PROD",
"CELERY_BROKER_URL": "amqp://lov",
"CELERY_RESULT_BACKEND": "cache+memory://openIMIS-test//"
Expand Down
7 changes: 4 additions & 3 deletions openIMIS/openIMIS/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..openimisapps import openimis_apps, get_locale_folders
from datetime import timedelta
from .common import DEBUG, BASE_DIR, MODE
from .common import DEBUG, BASE_DIR, MODE, protos, hosts
from .security import REMOTE_USER_AUTHENTICATION

# Makes openimis_apps available to other modules
Expand All @@ -17,6 +17,8 @@
def SITE_ROOT():
root = os.environ.get("SITE_ROOT", "")
if root == "":
if hosts and protos:
return f"{protos[0]}://{hosts[0]}/"
return root
elif root.endswith("/"):
return root
Expand All @@ -35,7 +37,7 @@ def SITE_URL():


SITE_FRONT = os.environ.get("SITE_FRONT", "front")
FRONTEND_URL = SITE_ROOT() + SITE_FRONT
FRONTEND_URL = os.environ.get("FRONTEND_URL", SITE_URL() + SITE_FRONT)

# Application definition

Expand Down Expand Up @@ -192,4 +194,3 @@ def SITE_URL():
# By default, the maximum upload size is 2.5Mb, which is a bit short for base64 picture upload
DATA_UPLOAD_MAX_MEMORY_SIZE = int(os.environ.get('DATA_UPLOAD_MAX_MEMORY_SIZE', 10 * 1024 * 1024))

FRONTEND_URL = os.environ.get("FRONTEND_URL", "")
3 changes: 3 additions & 0 deletions openIMIS/openIMIS/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MODE = os.environ.get("MODE", 'prod').lower()
# Fetch protocols and hosts from environment variables
protos = os.environ.get('PROTOS', default='https').split(',')
hosts = os.environ.get('HOSTS', default='localhost').split(',')
if MODE == "dev":
DEBUG = True
else:
Expand Down
9 changes: 3 additions & 6 deletions openIMIS/openIMIS/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from .common import hosts, protos

GRAPHQL_JWT.update({
"JWT_COOKIE_SECURE": True,
"JWT_COOKIE_SAMESITE": "Lax",
})


# Fetch protocols and hosts from environment variables
protos = os.environ.get('PROTOS', default='https').split(',')
hosts = os.environ.get('HOSTS', default='')

# Set ALLOWED_HOSTS
ALLOWED_HOSTS = hosts.split(',') if hosts else ['*']
ALLOWED_HOSTS = hosts if hosts else ['*']

# Create CSRF_TRUSTED_ORIGINS by combining protocols and hosts
CSRF_TRUSTED_ORIGINS = [f'{proto}://{host.strip()}' for proto in protos for host in ALLOWED_HOSTS if host != '*']
Expand Down
Loading