From b068225c72f159095b38137c38a5e26ed6e43911 Mon Sep 17 00:00:00 2001 From: nsde Date: Thu, 12 Oct 2023 00:07:30 +0200 Subject: [PATCH] Added docs --- README.md | 27 +++++++++++++++++++++++++++ web/account.py | 1 - web/app.py | 2 +- web/finances.py | 10 +++++++--- web/templates/index.html | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80185c9..728e597 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ # nova-web 🌐 [Website](https://nova-oss.com) of project Nova. + +## Set up your `.env` file + +```bash +CORE_API_URL="Used for accessing the database from nova-api. Usually, it's http://localhost:2333 (and :2332 for testing)." +CORE_API_KEY="The CORE_API_KEY set in the .env of nova-api." +CONTACT_EMAIL="The E-Mail address displayed on the website. Used for accessing databases." +TOS_VERIFICATION_KEY="Generate a password without special symbols and put it in here. Used in nova-cord." +DISCORD_CLIENT_ID="For 'auth using Discord' in the account dashboard. Get this from the Discord developer portal" +DISCORD_CLIENT_SECRET="For 'auth using Discord' in the account dashboard. Get this from the Discord developer portal" +FLASK_SECRET_KEY="Generate a password without special symbols and put it in here. It is used to encrypt the session cookie etc." +``` + +## Running +### Production +```bash +sh screen.sh +```` +or +```bash +python web +``` + +### Development +```bash +python web/app.py +```` diff --git a/web/account.py b/web/account.py index fa8de60..622d8cc 100755 --- a/web/account.py +++ b/web/account.py @@ -1,7 +1,6 @@ import os import flask import requests -import functools from dotenv import load_dotenv from requests_oauthlib import OAuth2Session diff --git a/web/app.py b/web/app.py index 4f29444..4748314 100755 --- a/web/app.py +++ b/web/app.py @@ -26,7 +26,7 @@ def create_app() -> flask.Flask: account.register(app) finances.register(app) - # max 100 MB + # max file size 100 MB (cloudflare limit) app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 @app.context_processor diff --git a/web/finances.py b/web/finances.py index c86c2b8..37b88c5 100755 --- a/web/finances.py +++ b/web/finances.py @@ -13,20 +13,24 @@ load_dotenv() # cache get_finances() for 5 minutes def get_finances(): - return requests.get( + res = requests.get( url=f'{os.environ["CORE_API_URL"]}/finances', headers={ 'Authorization': f'{os.environ["CORE_API_KEY"]}' }, timeout=5 - ).json() + ) + res.raise_for_status() + + return res.json() def register(app): @app.route('/finances') def finances_view(): try: data = get_finances() - except Exception: + except Exception as exc: + print(exc) return flask.Response('Error fetching finances from database. This might be cause the data is still being processed. Please allow up to a few minutes.', status=500) donations = data['donations'] diff --git a/web/templates/index.html b/web/templates/index.html index b8db60f..791f28f 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -7,7 +7,7 @@