diff --git a/README.md b/README.md index cb53b61..7853135 100644 --- a/README.md +++ b/README.md @@ -769,6 +769,32 @@ Docker Compose example: TLS: 1 ``` +#### Configure URL Prefix +`Available from Allure Docker Service version 2.13.X` + +Configure a url prefix if your deployment requires it (e.g. reverse proxy with nginx) +```sh + environment: + URL_PREFIX: "/reporting" +``` + +Here's an example config for nginx where `allure` is the name of the docker container +``` +server { + listen 443 ssl; + ssl_certificate /certificate.cer; + ssl_certificate_key /certificate.key; + location /reporting/ { + proxy_pass http://allure:5050; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } +} +``` + + #### Export Native Full Report `Available from Allure Docker Service version 2.13.1` diff --git a/allure-docker-api/app.py b/allure-docker-api/app.py index bd9ca4a..69baf4f 100644 --- a/allure-docker-api/app.py +++ b/allure-docker-api/app.py @@ -22,6 +22,7 @@ PROJECTS_DIRECTORY = os.environ['STATIC_CONTENT_PROJECTS'] EMAILABLE_REPORT_FILE_NAME = os.environ['EMAILABLE_REPORT_FILE_NAME'] ORIGIN='api' +URL_PREFIX = os.environ.get('URL_PREFIX', '') REPORT_INDEX_FILE = 'index.html' DEFAULT_TEMPLATE = 'default.html' @@ -61,8 +62,8 @@ SWAGGER_URL = '/allure-docker-service/swagger' API_URL = '/allure-docker-service/swagger.json' SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint( - SWAGGER_URL, - API_URL, + base_url = f'{URL_PREFIX}{SWAGGER_URL}', + api_url = f'{URL_PREFIX}{API_URL}', config = { 'app_name': "Allure Docker Service" } @@ -74,7 +75,7 @@ @app.route("/allure-docker-service", strict_slashes=False) def index(): try: - return render_template('index.html') + return render_template('index.html', url=f'{URL_PREFIX}/allure-docker-service/swagger') except Exception as ex: body = { 'meta_data': { @@ -89,7 +90,13 @@ def index(): @app.route("/allure-docker-service/swagger.json", strict_slashes=False) def swagger_json(): try: - return send_file("{}/swagger.json".format(STATIC_CONTENT), mimetype='application/json') + if URL_PREFIX: + with open("{}/swagger.json".format(STATIC_CONTENT), 'r') as f: + swagger_data = json.load(f) + swagger_data["servers"][0]["url"] = f'{URL_PREFIX}{swagger_data["servers"][0]["url"]}' + return jsonify(swagger_data) + else: + return send_file("{}/swagger.json".format(STATIC_CONTENT), mimetype='application/json') except Exception as ex: body = { 'meta_data': { @@ -852,4 +859,4 @@ def check_process(process_file, project_id): app.logger.info('Stating in DEV_MODE') app.run(host=HOST, port=PORT) else: - waitress.serve(app, threads=THREADS, host=HOST, port=PORT, url_scheme=URL_SCHEME) + waitress.serve(app, threads=THREADS, host=HOST, port=PORT, url_scheme=URL_SCHEME, url_prefix=URL_PREFIX) diff --git a/allure-docker-api/templates/index.html b/allure-docker-api/templates/index.html index 3fb16d1..6bb4daf 100644 --- a/allure-docker-api/templates/index.html +++ b/allure-docker-api/templates/index.html @@ -3,7 +3,7 @@