Skip to content

Commit

Permalink
feat(backend): use send_from_directory for testing instead of nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Jul 1, 2020
1 parent b7f76de commit f46b8b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Install the dependencies and run the application:
# install dependencies
pipenv install
# run the app
[FLASK_DEBUG=1] pipenv run -- flask run -h 0.0.0.0
[DOCAT_SERVE_FILES=1] [FLASK_DEBUG=1] pipenv run -- flask run -h 0.0.0.0
```

### Config Options

* **DOCAT_SERVE_FILES**: Serve static documentation instead of a nginx (for testing)
* **FLASK_DEBUG**: Start flask in debug mode

## Usage

See [getting-started.md](../doc/getting-started.md)
11 changes: 10 additions & 1 deletion docat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
:license: MIT, see LICENSE for more details.
"""

import os
from http import HTTPStatus
from pathlib import Path

from flask import Flask, request
from flask import Flask, request, send_from_directory
from werkzeug.utils import secure_filename

from docat.docat.utils import create_nginx_config, create_symlink, extract_archive
Expand Down Expand Up @@ -61,3 +62,11 @@ def tag(project, version, new_tag):
{"message": f"Tag {new_tag} would overwrite an existing version!"},
HTTPStatus.CONFLICT,
)


# serve_local_docs for local testing without a nginx
if os.environ.get("DOCAT_SERVE_FILES"):

@app.route("/doc/<path:path>")
def serve_local_docs(path):
return send_from_directory(app.config["UPLOAD_FOLDER"], path)

0 comments on commit f46b8b6

Please sign in to comment.