forked from kamo/exquisite-branch
env variables and url prefixer
parent
12152974e5
commit
7102ca7f4c
@ -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
|
@ -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()]
|
Loading…
Reference in New Issue