2024-11-13 03:23:11 +08:00
|
|
|
from flask import Flask
|
|
|
|
# from dotenv import load_dotenv
|
|
|
|
# load_dotenv()
|
|
|
|
import os
|
|
|
|
from sqlalchemy import create_engine
|
2024-11-14 13:03:00 +08:00
|
|
|
from utils.pgclass import Base
|
2024-11-13 03:23:11 +08:00
|
|
|
# blueprints
|
|
|
|
from blueprints.article import article
|
2024-11-14 13:03:00 +08:00
|
|
|
from blueprints.log import log
|
2024-11-13 03:23:11 +08:00
|
|
|
|
|
|
|
# Global Variables
|
|
|
|
PG_HOST = os.getenv("PG_HOST")
|
|
|
|
PG_PORT = os.getenv("PG_PORT")
|
|
|
|
PG_NAME = os.getenv("PG_NAME")
|
|
|
|
PG_USER = os.getenv("PG_USER")
|
|
|
|
PG_PASS = os.getenv("PG_PASS")
|
|
|
|
JWT_KEY = os.getenv("JWT_KEY")
|
|
|
|
|
|
|
|
# Postgresql
|
|
|
|
engine = create_engine('postgresql+psycopg2://%s:%s@%s:%s/%s'%(PG_USER, PG_PASS, PG_HOST, PG_PORT, PG_NAME))
|
|
|
|
Base.metadata.create_all(engine)
|
|
|
|
|
|
|
|
# shared class
|
|
|
|
class shared():
|
|
|
|
def __init__(self, engine):
|
|
|
|
self.engine = engine
|
|
|
|
sh = shared(engine)
|
|
|
|
|
|
|
|
# flask app
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config["SECRET_KEY"] = os.urandom(64)
|
|
|
|
app.shared_resource = sh
|
|
|
|
|
|
|
|
# register blueprints
|
|
|
|
app.register_blueprint(article, url_prefix = "/article")
|
2024-11-14 13:03:00 +08:00
|
|
|
app.register_blueprint(log , url_prefix = "/log")
|
2024-11-13 03:23:11 +08:00
|
|
|
|
|
|
|
# index
|
|
|
|
@app.route("/", methods = ["GET", "POST"])
|
|
|
|
def index():
|
2024-11-13 21:20:21 +08:00
|
|
|
return "Hello! World!<br>Shirakami Fubuki: cutest fox!!!"
|
2024-11-13 03:23:11 +08:00
|
|
|
|
|
|
|
# app run
|
|
|
|
if __name__ == "__main__":
|
2024-11-12 21:12:23 +08:00
|
|
|
app.run(host="0.0.0.0", port=5000, debug=False)
|