mirror of
https://github.com/kevin-DL/ShortMe-URL-Shortener.git
synced 2026-01-15 12:44:45 +00:00
Initial commit
This commit is contained in:
26
app/setup/settings.py
Normal file
26
app/setup/settings.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI')
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = os.environ.get('SQLALCHEMY_TRACK_MODIFICATIONS')
|
||||
ADMIN_USERNAME = os.environ.get('ADMIN_USERNAME')
|
||||
ADMIN_PASSWORD = os.environ.get('ADMIN_PASSWORD')
|
||||
|
||||
MAIL_SERVER = os.environ.get('MAIL_SERVER')
|
||||
MAIL_PORT = int(os.environ.get('MAIL_PORT'))
|
||||
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
|
||||
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
||||
MAIL_USE_TLS = False
|
||||
MAIL_USE_SSL = True
|
||||
|
||||
"""
|
||||
:::::::: .env file content ::::::::
|
||||
SQLALCHEMY_DATABASE_URI=sqlite:///db.sqlite3
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS=False
|
||||
SECRET_KEY=randomKey
|
||||
|
||||
MAIL_SERVER=smtp.gmail.com
|
||||
MAIL_PORT=465
|
||||
MAIL_USERNAME=email@email.com
|
||||
MAIL_PASSWORD=password
|
||||
"""
|
||||
69
app/setup/setup.py
Normal file
69
app/setup/setup.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# ------- standard library imports -------
|
||||
import os
|
||||
|
||||
# ------- 3rd party imports -------
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# ------- local imports -------
|
||||
from app.server.db.extensions import db
|
||||
from app.server.db.models import AuthToken
|
||||
from app.server.routes.index import index_blueprint
|
||||
from app.server.routes.internal.redirect_to_url import redirect_to_url_blueprint
|
||||
from app.server.routes.internal.favicon import app_blueprint
|
||||
from app.server.routes.internal.send_verification_code import send_otp_blueprint
|
||||
from app.server.routes.internal.shorten_url import shorten_url_blueprint
|
||||
from app.server.routes.your_short_url import your_short_url_blueprint
|
||||
from app.server.routes.total_clicks import total_clicks_blueprint
|
||||
from app.server.routes.error import error_blueprint
|
||||
from app.server.routes.page_not_found import page_not_found_blueprint
|
||||
from app.server.routes.api_doc import api_doc_blueprint
|
||||
from app.server.routes.get_token import get_token_blueprint
|
||||
from app.server.routes.your_api_token import your_api_token_blueprint
|
||||
from app.server.routes.verify_code import verify_code_blueprint
|
||||
|
||||
from app.server.api.api import Shorten, TotalClicks, GetToken
|
||||
|
||||
|
||||
def create_app(config_file):
|
||||
"""
|
||||
Creating and returning the app
|
||||
"""
|
||||
app_path = os.path.dirname(os.path.abspath(__file__))
|
||||
project_folder = os.path.expanduser(app_path)
|
||||
load_dotenv(os.path.join(project_folder, '.env'))
|
||||
|
||||
app = Flask(__name__, template_folder='../client/templates', static_folder='../client/static')
|
||||
api = Api(app)
|
||||
app.config.from_pyfile(config_file)
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
|
||||
app_auth_token = app.secret_key
|
||||
auth_token = AuthToken(auth_token=app_auth_token)
|
||||
db.session.add(auth_token)
|
||||
db.session.commit()
|
||||
|
||||
api.add_resource(Shorten, '/api/shorten')
|
||||
api.add_resource(GetToken, '/api/get_token')
|
||||
api.add_resource(TotalClicks, '/api/total_clicks')
|
||||
|
||||
app.register_blueprint(index_blueprint)
|
||||
app.register_blueprint(page_not_found_blueprint)
|
||||
app.register_blueprint(redirect_to_url_blueprint)
|
||||
app.register_blueprint(your_short_url_blueprint)
|
||||
app.register_blueprint(total_clicks_blueprint)
|
||||
app.register_blueprint(error_blueprint)
|
||||
app.register_blueprint(app_blueprint)
|
||||
app.register_blueprint(api_doc_blueprint)
|
||||
app.register_blueprint(get_token_blueprint)
|
||||
app.register_blueprint(send_otp_blueprint)
|
||||
app.register_blueprint(verify_code_blueprint)
|
||||
app.register_blueprint(your_api_token_blueprint)
|
||||
app.register_blueprint(shorten_url_blueprint)
|
||||
return app
|
||||
Reference in New Issue
Block a user