env variables and url prefixer

master
km0 3 years ago
parent 12152974e5
commit 7102ca7f4c

2
.gitignore vendored

@ -13,3 +13,5 @@ htmlcov/
dist/
build/
*.egg-info/
.env

@ -0,0 +1,15 @@
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

@ -1,23 +1,6 @@
import os
from flask import Flask
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()]
from . import prefix
def create_app(test_config=None):
# create and configure the app
@ -55,6 +38,8 @@ def create_app(test_config=None):
from . import home
app.register_blueprint(home.bp)
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/xquisite')
app.wsgi_app = prefix.PrefixMiddleware(app.wsgi_app, prefix=os.environ.get("URL_PREFIX", ''))
return app

@ -0,0 +1,15 @@
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()]

@ -8,6 +8,7 @@ setup(
zip_safe=False,
install_requires=[
'flask',
'shortuuid'
'shortuuid',
'python-dotenv'
],
)

Loading…
Cancel
Save