Skip to content

Commit

Permalink
#114 - Support URL_PREFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
apulverizer authored and fescobar committed Aug 10, 2020
1 parent 3be6843 commit 9263783
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
17 changes: 12 additions & 5 deletions allure-docker-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
}
Expand All @@ -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': {
Expand All @@ -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': {
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion allure-docker-api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Allure Docker Service</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon') }}">
<meta http-equiv="Refresh" content="0; url=/allure-docker-service/swagger"/>
<meta http-equiv="Refresh" content="0; url={{url}}"/>
</head>

<body>
Expand Down

0 comments on commit 9263783

Please sign in to comment.