mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-25 01:02:19 +00:00
WIP
This commit is contained in:
parent
07ded54d4d
commit
2f10b99e06
2 changed files with 14 additions and 18 deletions
|
@ -6,7 +6,7 @@ import datetime
|
|||
import pretty
|
||||
|
||||
from get_args import args
|
||||
from config import settings
|
||||
from config import settings, base_url
|
||||
|
||||
from init import *
|
||||
import logging
|
||||
|
@ -19,7 +19,7 @@ from flask import Flask, jsonify, request, Response, Blueprint
|
|||
|
||||
from flask_restful import Resource, Api
|
||||
|
||||
api_bp = Blueprint('api', __name__, url_prefix='/api')
|
||||
api_bp = Blueprint('api', __name__, url_prefix=base_url.rstrip('/')+'/api')
|
||||
api = Api(api_bp)
|
||||
|
||||
|
||||
|
|
|
@ -65,27 +65,23 @@ from flask_debugtoolbar import DebugToolbarExtension
|
|||
from functools import wraps
|
||||
|
||||
|
||||
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()]
|
||||
def prefix_route(route_function, prefix='', mask='{0}{1}'):
|
||||
# Defines a new route function with a prefix.
|
||||
# The mask argument is a `format string` formatted with, in that order: prefix, route
|
||||
def newroute(route, *args, **kwargs):
|
||||
# New function to prefix the route
|
||||
return route_function(mask.format(prefix, route), *args, **kwargs)
|
||||
return newroute
|
||||
|
||||
# Flask Setup
|
||||
app = Flask(__name__,
|
||||
template_folder=os.path.join(os.path.dirname(__file__), '..', 'views'),
|
||||
static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'))
|
||||
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=base_url)
|
||||
app.route = prefix_route(app.route, base_url.rstrip('/'))
|
||||
|
||||
@app.errorhandler(404)
|
||||
def http_error_handler(error):
|
||||
return redirect(base_url.rstrip('/')), 302
|
||||
|
||||
app.config["SECRET_KEY"] = 'test'
|
||||
|
||||
|
|
Loading…
Reference in a new issue