-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
38 lines (32 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Main application layer for the server.
"""
import os
from flask import Flask
from dotenv import dotenv_values
from server.views import PageRoutes
from server.api import ApiRoutes
from database import DatabaseSettings
from database import create_database_handler
# Constants
ENV_CONFIGS: dict = dotenv_values(".env")
TEMPLATES_DIR: str = "server/templates"
STATIC_DIR: str = "server/static"
# Create the Flask server.
app = Flask(__name__, template_folder=TEMPLATES_DIR, static_folder=STATIC_DIR)
# Secret key
secret_key = os.environ.get('SECRET_KEY')
app.secret_key = secret_key
# Create the database handler.
database_settings = DatabaseSettings(
name=ENV_CONFIGS['DATABASE_NAME'],
host=ENV_CONFIGS['DATABASE_HOST'],
port=ENV_CONFIGS['DATABASE_PORT'],
username=ENV_CONFIGS['DATABASE_USERNAME'],
password=ENV_CONFIGS['DATABASE_PASSWORD']
)
database_handler = create_database_handler(database_settings)
database_handler.connect()
# Register the routes for page views and REST API.
app.register_blueprint(PageRoutes)
app.register_blueprint(ApiRoutes)