niming_backend/app.py

44 lines
1.1 KiB
Python
Raw Normal View History

from flask import Flask
2024-11-07 16:55:35 +08:00
from dotenv import load_dotenv
load_dotenv()
import os
from sqlalchemy import create_engine
from pgclass import Base, SQLarticle
# blueprints
from blueprints.article import article
# 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
self.SQLarticle = SQLarticle
sh = shared(engine)
# flask app
2024-11-07 02:19:53 +08:00
app = Flask(__name__)
app.config["SECRET_KEY"] = os.urandom(64)
app.shared_resource = sh
2024-11-07 16:55:35 +08:00
# register blueprints
app.register_blueprint(article, url_prefix = "/article")
2024-11-07 16:55:35 +08:00
# index
@app.route("/", methods = ["GET", "POST"])
def index():
return "Hello, World!"
2024-11-07 02:19:53 +08:00
# app run
2024-11-07 02:19:53 +08:00
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=False)