Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve static files #37

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ flask --app backend.btviewer.app --debug run

To run the frontend user interface in development mode, see the [frontend contribution guide](../frontend/CONTRIBUTING.md).

## Deployment

The Python package is built and published by a GitHub Actions workflow.

To test the installation of the package in a separate environment, you can install it directly from GitHub using the [VCS support](https://pip.pypa.io/en/stable/topics/vcs-support/) feature of `pip install`. For example:

```bash
branch="my_name"
pip install git+https://github.com/SheffieldMLtracking/btviewer@$branch#subdirectory=backend
```



## Further reading

- Flask [Project Layout](https://flask.palletsprojects.com/en/2.3.x/tutorial/layout/) and [tutorial example](https://github.com/pallets/flask/tree/3.0.2/examples/tutorial)
15 changes: 11 additions & 4 deletions backend/btviewer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ def get_args() -> argparse.Namespace:
return parser.parse_args()


def configure_logging(log_level):
# https://flask.palletsprojects.com/en/2.3.x/logging/
# https://docs.pylonsproject.org/projects/waitress/en/stable/logging.html
logging.basicConfig(level=log_level)

for name in {'waitress', 'werkzeug'}:
logging.getLogger(name).setLevel(log_level)


def main():
args = get_args()
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
configure_logging(logging.DEBUG if args.verbose else logging.INFO)

# Create WSGI app
app = btviewer.app_factory.create_app(root_directory=args.root_directory)
Expand All @@ -55,11 +64,9 @@ def main():

# Open frontend in web browser
static_uri = uri + '/static/index.html'
logging.info('Front end %s', static_uri)
webbrowser.open(static_uri)

print('flask where')
print(flask.url_for('static', filename='index.html'))

# Run web server
# https://docs.pylonsproject.org/projects/waitress/en/latest/arguments.html
waitress.serve(app, host=args.host, port=args.port, threads=args.threads)
Expand Down
15 changes: 15 additions & 0 deletions backend/btviewer/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>btviewer development 🐝</title>
</head>
<body>
<h1>Hello, world! 🐝</h1>
<p>
You are running this app in development mode.
</p>
<p>
This HTML file will be overwritten with the front-end code.
</p>
</body>
</html>