mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Well, this works
This commit is contained in:
parent
08993451e0
commit
860172916e
5 changed files with 35 additions and 17 deletions
12
royalnet/royalgamesweb.py
Normal file
12
royalnet/royalgamesweb.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
import os
|
||||
from .web import create_app
|
||||
from .web.blueprints import helloworld
|
||||
|
||||
|
||||
class TestConfig:
|
||||
DB_PATH = os.environ["DB_PATH"]
|
||||
REQUIRED_TABLES = set()
|
||||
|
||||
|
||||
app = create_app(TestConfig, [helloworld.bp])
|
||||
app.run()
|
|
@ -0,0 +1,3 @@
|
|||
from .flaskserver import create_app
|
||||
|
||||
__all__ = ["create_app"]
|
|
@ -4,12 +4,12 @@ import werkzeug.local
|
|||
|
||||
def get_alchemy_session():
|
||||
if "alchemy_session" not in f.g:
|
||||
f.g.alchemy_session = f.current_app.config["RN_ALCHEMY"].Session()
|
||||
f.g.alchemy_session = f.g.alchemy.Session()
|
||||
return f.g.alchemy_session
|
||||
|
||||
|
||||
@f.current_app.teardown_appcontext
|
||||
def teardown_alchemy_session(*args, **kwargs):
|
||||
def teardown_alchemy_session(*_, **__):
|
||||
_alchemy_session = f.g.pop("alchemy_session", None)
|
||||
if _alchemy_session is not None:
|
||||
_alchemy_session.close()
|
||||
|
|
9
royalnet/web/blueprints/helloworld.py
Normal file
9
royalnet/web/blueprints/helloworld.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import flask as f
|
||||
|
||||
|
||||
bp = f.Blueprint("helloworld", __name__, url_prefix="/helloworld")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def helloworld():
|
||||
return "Hello world!"
|
|
@ -1,19 +1,13 @@
|
|||
import typing
|
||||
import flask as f
|
||||
import os
|
||||
from ..database import Alchemy
|
||||
|
||||
|
||||
def create_app(config_obj: typing.Type, blueprints: typing.List[f.Blueprint]):
|
||||
app = f.Flask(__name__)
|
||||
app.config["RN_ALCHEMY"] = Alchemy(os.environ["DB_PATH"], set())
|
||||
app.config.from_object(config_obj)
|
||||
with app.app_context():
|
||||
from .alchemyhandler import alchemy_session as db_session
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def test():
|
||||
...
|
||||
return repr(db_session)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
f.g.alchemy = Alchemy(app.config["DB_PATH"], app.config["REQUIRED_TABLES"])
|
||||
for blueprint in blueprints:
|
||||
app.register_blueprint(blueprint)
|
||||
return app
|
||||
|
|
Loading…
Reference in a new issue