Added environment variables

This commit is contained in:
xemeds
2021-12-24 23:12:32 +03:00
parent 6fc7a7f395
commit 196bd81b46
4 changed files with 29 additions and 20 deletions

View File

@@ -32,17 +32,19 @@ Visit the below URL to view the flask app:
If you do not have a dedicated server, I highly recommend using [Linode](https://www.linode.com/), [Heroku](https://www.heroku.com/) or [PythonAnywhere](https://www.pythonanywhere.com/) to host your application.
Before deploying, in the file:
Before deploying, make sure to set the following environment variables:
tiny0/run.py
$ export WEBSITE_DOMAIN=
$ export SECRET_KEY=
$ export DEBUG=
$ export SQLALCHEMY_DATABASE_URI=
set running in debug mode to False:
If not they will default to the following values:
app.run(debug=False)
and change the config file located in the directory below:
tiny0/tiny0/config.json
WEBSITE_DOMAIN=127.0.0.1:5000
SECRET_KEY=SECRET_KEY
DEBUG=true
SQLALCHEMY_DATABASE_URI=sqlite:///database.db
# License

3
run.py
View File

@@ -1,4 +1,5 @@
from tiny0 import app
from tiny0.config import DEBUG
if __name__ == '__main__':
app.run(debug=True)
app.run(debug=DEBUG)

View File

@@ -1,5 +0,0 @@
{
"WEBSITE_DOMAIN":"127.0.0.1:5000",
"SECRET_KEY": "SECRET_KEY",
"SQLALCHEMY_DATABASE_URI": "sqlite:///database.db"
}

View File

@@ -1,9 +1,20 @@
import json
import os
from distutils.util import strtobool
with open("tiny0/config.json", "r") as config_file:
WEBSITE_DOMAIN = os.environ.get("WEBSITE_DOMAIN")
if not WEBSITE_DOMAIN:
WEBSITE_DOMAIN = "127.0.0.1:5000"
config_data = json.load(config_file)
SECRET_KEY = os.environ.get("SECRET_KEY")
if not SECRET_KEY:
SECRET_KEY = "SECRET_KEY"
WEBSITE_DOMAIN = config_data.get("WEBSITE_DOMAIN")
SECRET_KEY = config_data.get("SECRET_KEY")
SQLALCHEMY_DATABASE_URI = config_data.get("SQLALCHEMY_DATABASE_URI")
SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI")
if not SQLALCHEMY_DATABASE_URI:
SQLALCHEMY_DATABASE_URI = "sqlite:///database.db"
DEBUG = os.environ.get("DEBUG")
if not DEBUG:
DEBUG = "true"
DEBUG = strtobool(DEBUG)