From 811a9cf8160092a439fdf886cd9a577fdada290e Mon Sep 17 00:00:00 2001 From: "kam (from the studio)" Date: Mon, 3 Oct 2022 20:13:24 +0200 Subject: [PATCH] env var --- requirements.txt | 2 +- workbook.py | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index aa60c37..56576ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,6 @@ importlib-metadata==4.11.4 itsdangerous==2.1.2 Jinja2==3.1.2 MarkupSafe==2.1.1 -PyYAML==6.0 Werkzeug==2.1.2 zipp==3.8.0 +python-dotenv==0.21.0 \ No newline at end of file diff --git a/workbook.py b/workbook.py index 5bb2c4e..17a9670 100644 --- a/workbook.py +++ b/workbook.py @@ -1,14 +1,11 @@ from flask import Flask, render_template, request, redirect, url_for, jsonify from werkzeug.utils import secure_filename - import json -from pathlib import Path - import sqlite3 +from dotenv import load_dotenv +from pathlib import Path +import os -Path(f'static/panels/').mkdir(exist_ok=True) -Path(f'static/cables/').mkdir(exist_ok=True) -Path(f'static/snippets/').mkdir(exist_ok=True) class PrefixMiddleware(object): def __init__(self, app, prefix=""): @@ -16,7 +13,7 @@ class PrefixMiddleware(object): self.prefix = prefix def __call__(self, environ, start_response): - + if environ["PATH_INFO"].startswith(self.prefix): environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :] environ["SCRIPT_NAME"] = self.prefix @@ -26,11 +23,16 @@ class PrefixMiddleware(object): return ["This url does not belong to the app.".encode()] -app = Flask(__name__) +load_dotenv() +Path(f'static/panels/').mkdir(exist_ok=True) +Path(f'static/cables/').mkdir(exist_ok=True) +Path(f'static/snippets/').mkdir(exist_ok=True) + +app = Flask(__name__) # register the middleware to prefix all the requests with our base_url -app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/workbook') +app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=os.environ.get('BASE_URL', '')) def get_db_connection():