summaryrefslogtreecommitdiff
path: root/web-server
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-30 17:26:19 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:44:35 +0200
commitcac980546e15882a232ce234cbde3e0cda693352 (patch)
tree50fed18858c6c5cbb11c3ecb690ebbff8bc98525 /web-server
parent80730074581b8a934fb5b064a54912f620fad978 (diff)
Get Docker setup working
Diffstat (limited to 'web-server')
-rw-r--r--web-server/OpenDC.postman_collection.json61
-rw-r--r--web-server/main.py9
-rw-r--r--web-server/opendc/util/database.py2
3 files changed, 9 insertions, 63 deletions
diff --git a/web-server/OpenDC.postman_collection.json b/web-server/OpenDC.postman_collection.json
deleted file mode 100644
index c34dc310..00000000
--- a/web-server/OpenDC.postman_collection.json
+++ /dev/null
@@ -1,61 +0,0 @@
-{
- "variables": [],
- "info": {
- "name": "OpenDC",
- "_postman_id": "e8b68f59-29cb-71d0-6237-b22932c40f9c",
- "description": "Sample requests for developing the OpenDC API",
- "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
- },
- "item": [
- {
- "name": "Create New Simulation",
- "request": {
- "url": "localhost:8081/api/v1/simulations",
- "method": "POST",
- "header": [
- {
- "key": "Content-Type",
- "value": "application/json",
- "description": ""
- },
- {
- "key": "auth-token",
- "value": "PUT YOUR AUTH TOKEN HERE",
- "description": ""
- }
- ],
- "body": {
- "mode": "raw",
- "raw": "{\r\n \"simulation\": {\r\n \"name\": \"Simulation Name\"\r\n }\r\n}"
- },
- "description": ""
- },
- "response": []
- },
- {
- "name": "Create New User",
- "request": {
- "url": "localhost:8081/api/v1/users",
- "method": "POST",
- "header": [
- {
- "key": "Content-Type",
- "value": "application/json",
- "description": ""
- },
- {
- "key": "auth-token",
- "value": "PUT YOUR AUTH TOKEN HERE",
- "description": ""
- }
- ],
- "body": {
- "mode": "raw",
- "raw": "{\r\n \"user\": {\r\n \"email\": \"email@example.com\"\r\n }\r\n}"
- },
- "description": ""
- },
- "response": []
- }
- ]
-} \ No newline at end of file
diff --git a/web-server/main.py b/web-server/main.py
index 6d2f8747..94696e8d 100644
--- a/web-server/main.py
+++ b/web-server/main.py
@@ -15,17 +15,24 @@ from opendc.util.exceptions import AuthorizationTokenError, RequestInitializatio
TEST_MODE = "OPENDC_FLASK_TESTING" in os.environ
+# Specify the directory of static assets
if TEST_MODE:
STATIC_ROOT = os.curdir
else:
+ STATIC_ROOT = os.path.join(os.environ['OPENDC_ROOT_DIR'], 'frontend', 'build')
+
+# Set up database if not testing
+if not TEST_MODE:
database.DB.initialize_database(user=os.environ['OPENDC_DB_USERNAME'],
password=os.environ['OPENDC_DB_PASSWORD'],
database=os.environ['OPENDC_DB'],
host='localhost')
- STATIC_ROOT = os.path.join(os.environ['OPENDC_ROOT_DIR'], 'opendc-frontend', 'build')
+# Set up the core app
FLASK_CORE_APP = Flask(__name__, static_url_path='', static_folder=STATIC_ROOT)
FLASK_CORE_APP.config['SECRET_KEY'] = os.environ['OPENDC_FLASK_SECRET']
+
+# Set up CORS support for local setups
if 'localhost' in os.environ['OPENDC_SERVER_BASE_URL']:
CORS(FLASK_CORE_APP)
diff --git a/web-server/opendc/util/database.py b/web-server/opendc/util/database.py
index 12d6afc9..0402c2e1 100644
--- a/web-server/opendc/util/database.py
+++ b/web-server/opendc/util/database.py
@@ -14,7 +14,7 @@ class Database:
def __init__(self):
self.opendc_db = None
- def init_database(self, user, password, database, host):
+ def initialize_database(self, user, password, database, host):
"""Initializes the database connection."""
user = urllib.parse.quote_plus(user)