From cc4f18c10946e26f2cf6b1cdf9be16edcfc25c64 Mon Sep 17 00:00:00 2001 From: "kam (from the studio)" Date: Thu, 24 Mar 2022 20:47:13 +0100 Subject: [PATCH] init repo soup --- .gitignore | 18 ++++++++++++++++++ config.py | 18 ++++++++++++++++++ setup.py | 10 ++++++++++ soup_app/__init__.py | 0 soup_app/home.py | 8 ++++++++ soup_app/prefix.py | 14 ++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 config.py create mode 100644 setup.py create mode 100644 soup_app/__init__.py create mode 100644 soup_app/home.py create mode 100644 soup_app/prefix.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..891315c --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +venv/ + +*.pyc +__pycache__/ +.ipynb_checkpoints + +instance/ + +.pytest_cache/ +.coverage +htmlcov/ + +dist/ +build/ +*.egg-info/ + +.env +.vscode \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..745f39b --- /dev/null +++ b/config.py @@ -0,0 +1,18 @@ +import os + + +class Config(object): + DEBUG = False + TESTING = False + URL_PREFIX = "" + + +class ProductionConfig(Config): + DEBUG = False + URL_PREFIX = os.environ.get("URL_PREFIX") + + +class DevelopmentConfig(Config): + ENV = "development" + DEVELOPMENT = True + DEBUG = True diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6205920 --- /dev/null +++ b/setup.py @@ -0,0 +1,10 @@ +from setuptools import find_packages, setup + +setup( + name="soup_app", + version="1.0.0", + packages=find_packages(), + include_package_data=True, + zip_safe=False, + install_requires=["flask", "python-dotenv", "python-frontmatter"], +) diff --git a/soup_app/__init__.py b/soup_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/soup_app/home.py b/soup_app/home.py new file mode 100644 index 0000000..39b9c79 --- /dev/null +++ b/soup_app/home.py @@ -0,0 +1,8 @@ +from flask import Blueprint + +bp = Blueprint("home", __name__, url_prefix="/") + + +@bp.route("/") +def home(): + return 'Hello world' \ No newline at end of file diff --git a/soup_app/prefix.py b/soup_app/prefix.py new file mode 100644 index 0000000..a94e608 --- /dev/null +++ b/soup_app/prefix.py @@ -0,0 +1,14 @@ +class PrefixMiddleware(object): + def __init__(self, app, prefix=""): + self.app = app + 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 + return self.app(environ, start_response) + else: + start_response("404", [("Content-Type", "text/plain")]) + return ["This url does not belong to the app.".encode()]